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默认的分类标题显示只能是你后台显示什么, 那么调用出来就是什么, 但是我们自己可以自定义一些功能, 如何实现? 下面看看这个
直接把下面的这串代码复制到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里面点击保存
<?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 . ", "; } } ?>
<?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); ?>" />
最后就可以实现, 源代码里面展示的标题和我们看到的标题有不一样了, 我们可以自己在分类目录里面编辑.