摘要:在当前主题的functions.php文件中添加以下代码: [crayon-65b8d1556467a345391914…
在当前主题的functions.php文件中添加以下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<?php
global $texonomy_slug_keywords;
$texonomy_slug_keywords=‘category’;
add_action($texonomy_slug_keywords.‘_add_form_fields’,‘categorykeywords’);
function categorykeywords($taxonomy){ ?>
<div>
<label for=“tag-keywords”>分类关键词</label>
<input type=“text” name=“tag-keywords” id=“tag-keywords” value=“” /><br /><span>请在此输入分类关键词。</span>
</div>
<?php }
add_action($texonomy_slug_keywords.‘_edit_form_fields’,‘categorykeywordsedit’);
function categorykeywordsedit($taxonomy){ ?>
<tr class=“form-field”>
<th scope=“row” valign=“top”><label for=“tag-keywords”>关键词</label></th>
<td><input type=“text” name=“tag-keywords” id=“tag-keywords” value=“<?php echo get_option(‘_category_keywords’.$taxonomy->term_id); ?>“ /><br /><span class=“description”>请在此输入分类关键词。</span></td>
</tr>
<?php }
add_action(‘edit_term’,‘categorykeywordssave’);
add_action(‘create_term’,‘categorykeywordssave’);
function categorykeywordssave($term_id){
if(isset($_POST[‘tag-keywords’])){
if(isset($_POST[‘tag-keywords’]))
update_option(‘_category_keywords’.$term_id,$_POST[‘tag-keywords’] );
}
}
?>
|
在header.php文件中添加该字段内容作为分类keywords:
1
2
3
4
5
6
7
8
|
<?php
if(is_category()){
$category_info = get_the_category();
$category_id = $category_info[0]->cat_ID;
$cat_keywords = get_option(‘_category_keywords’.$category_id);
?>
<meta name=“keywords” content=“<?php echo $cat_keywords;?>“/>
<?php } ?>
|
来源:http://www.wazhuti.com/737.html