1. 在模板目录下的 function.php 里,插入以下代码,用于添加包含 页面 category_field.php。
// 分类添加字段
require_once( dirname(__FILE__).‘/category_field.php’ );
2. 新建 category_field.php 页面,代码如下:
// 分类添加字段
function ems_add_category_field(){
echo ‘';The telephone.
echo ‘';The URL.
}
add_action(‘category_add_form_fields’,’ems_add_category_field’,10,2);
// 分类编辑字段
function ems_edit_category_field($tag){
echo ‘';
echo get_option(‘cat-tel-‘.$tag->term_id).’” size=”40″/>
‘.$tag->name.’ on the phone.
echo ‘';
echo get_option(‘cat-url-‘.$tag->term_id).’” size=”40″/>
‘.$tag->name.’ on the URL.
}
add_action(‘category_edit_form_fields’,’ems_edit_category_field’,10,2);
// 保存数据
function ems_taxonomy_metadate($term_id){
if(isset($_POST[‘cat-tel’]) && isset($_POST[‘cat-url’])){
//判断权限–可改
if(!current_user_can(‘manage_categories’)){
return $term_id;
}
// 电话
$tel_key = ‘cat-tel-‘.$term_id; // key 选项名为 cat-tel-1 类型
$tel_value = $_POST[‘cat-tel’]; // value
// url
$url_key = ‘cat-url-‘.$term_id;
$url_value = $_POST[‘cat-url’];
// 更新选项值
update_option( $tel_key, $tel_value );
update_option( $url_key, $url_value );
}
}
// 虽然要两个钩子,但是我们可以两个钩子使用同一个函数
add_action(‘created_category’,’ems_taxonomy_metadate’,10,1);
add_action(‘edited_category’,’ems_taxonomy_metadate’,10,1);
?>
3、调用方法(可以在wordpress文章模板(single.php)调用分类的META信息)。
// 取出当前分类 id: $categories[0]->term_id
$categories = get_the_category();
$term_id = $categories[0]->term_id;
$cat_name = $categories[0]->name;
?>
4.以上是通过代码的方式给分类目录添加META属性字段信息。
在发表文章时, 可以通过”添加媒体“来上传视频; 也可以把视频链接地址直接复制到文章内容中(如优酷视频) 这样就可以了。 希望帮到你了。