当前位置:首页 >>wordpress使用教程 > 正文

wordpress怎么给分类添加长标题;分类目录如何增加不一样的描述和标题?


Warning: Undefined variable $post_id in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 263
百度: 已收录 | 发布日期:2022-06-01 12:39:46 | 浏览:420 次


Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133

Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133

Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134

Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134

Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 136

Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 138

Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133

Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133

Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134

Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134

Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 136

Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 138

wordpress怎么给分类添加长标题(分类目录如何增加不一样的描述和标题? )

wordpress怎么给分类添加长标题, 经常需要给自己的网站定制一些别的功能, wordpress默认的分类标题显示只能是你后台显示什么, 那么调用出来就是什么, 但是我们自己可以自定义一些功能, 如何实现? 下面看看这个

一、给分类后台增加一个选框

直接把下面的这串代码复制到functions.php模板中, 然后保存.

//分类目录 SEO 优化
add_action('edit_category_form_fields', 'category_function');
function category_function(){
if(isset($_GET['action']) && $_GET['action'] == 'edit') $value = get_option('cat_set_' . $_GET['tag_ID']);
$title = 'cat_title';
$keywords = 'cat_keywords';
//$description = 'cat_description';
?>
<table class="form-table">
</table>
<h2>自定义SEO信息</h2>
<table class="form-table">
<tbody>
<tr class="form-field">
<th scope="row" valign="top"><label for="<?php echo $title ?>">标题</label></th>
<td>
<input name="<?php echo $title ?>" id="<?php echo $title ?>" type="text" value="<?php echo esc_attr(stripslashes($value['title']));?>">
<p class="description">默认调用分类名称作为Head中Title信息. </p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="<?php echo $keywords; ?>">关键词</label></th>
<td>
<input name="<?php echo $keywords; ?>" id="<?php echo $keywords; ?>" type="text" value="<?php echo $value['keywords'];?>">
<p class="description">多个关键词用小写逗号","分隔开;默认调用分类名称作为Head中KeyWords信息. </p>
</td>
</tr>
<!--<tr class="form-field">
<th scope="row" valign="top"><label for="<?php echo $description; ?>">描述</label></th>
<td>
<textarea name="<?php echo $description; ?>" id="<?php echo $description; ?>" rows="3" cols="30">
<?php echo stripslashes($value['description']); ?>
</textarea>
<p class="description">若未设置, 将显示为"关于‘某某’分类下的所有文章. "作为Head中Description信息. </p>
</td>
</tr>-->
</tbody>
</table>

<?php
}
add_action('edit_category', 'save_category_function');
function save_category_function(){
if(isset($_POST['action']) && isset($_POST['taxonomy']) && $_POST['action'] == 'editedtag' && $_POST['taxonomy'] == 'category'){
update_option(
'cat_set_' . $_POST['tag_ID'],
array(
'title' => $_POST['cat_title'],
//'description' => $_POST['cat_description'],
'keywords' => $_POST['cat_keywords'],
'template' => $_POST['cat_template'],
'orderby' => $_POST['cat_orderby'],
'per_page' => $_POST['cat_per_page'],
)
);
}
};

二、我们还需要新建立一个头部文件 header-seo.php

然后把下面的这串代码粘贴到header-seo.php里面点击保存

<?php
if (is_home()){ //首页SEO
$title =get_bloginfo('description')." - ".get_bloginfo('name');
$description = get_option('swt_description');
$keywords = get_option('swt_keywords');

}elseif (is_category()){ //分类目录SEO

$cat_id = get_query_var('cat');
$val = get_option("cat_set_$cat_id");
//分类目录长标题
if(!Empty($val) && $val['title']!=''){
$title = $val['title'].' - '.get_bloginfo('name');
}else{
$title = single_cat_title('', false).' - '.get_bloginfo('name');
}
//分类目录关键词
if(!Empty($val) && $val['keywords']!=''){
$keywords = $val['keywords'];
}else{
$keywords = single_cat_title('', false);
}
//分类目录描述
$description = category_description();

}elseif (is_tag()){ //标签页

$title = single_cat_title('', false).' - '.get_bloginfo('name');
$description = tag_description();
$keywords = single_tag_title('', false);

}elseif (is_single()){ //文章页

$title = $post->post_title.' - '.get_bloginfo('name');
if ($post->post_excerpt){
$description = $post->post_excerpt;
} else {
$description = substr(strip_tags($post->post_content),0,400);
}
$keywords = "";
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ){
$keywords = $keywords . $tag->name . ", ";
}
}
?>

三、我们还需要在头部文件header.php里面把它调用出来

<?php include "header-seo.php"; ?>
<title><?php echo $title; ?></title>
<meta name="keywords" content="<?php echo $keywords ?>" />
<meta name="description" content="<?php echo strip_tags($description); ?>" />

最后就可以实现, 源代码里面展示的标题和我们看到的标题有不一样了, 我们可以自己在分类目录里面编辑.

99%的人还阅读了:

版权声明:本文由作者:卡卡哥服务器教程网 原创创作,本站内容不允许转载,如发现转载必追究法律责任!! 本文链接:https://yunfuwuqi.chinahzx.cn/wordpress/198.html