制作一款好的WordPress主题,很多细节都需要考虑,尤其是SEO和用户体验。今天主要分享下,在WordPress分类存档页面,显示分类的标题、描述和RSS订阅的方法。
一般我们的分类存档模板文件为 category.php 或 archive.php ,你可以在面包屑导航与文章列表的中间输出分类标题、描述等信息,如下图所示:

一般建议给主题添加一个 category.php 文件,因为是它专门用来显示分类存档的,优先级别高于 archive.php 。如果主题没有 category.php ,你可以直接复制 archive.php 的代码,另存为 category.php 即可。
输出分类标题:
<?php echo single_cat_title( '', false ) ; ?> |
<?php echo single_cat_title( '', false ) ; ?>
输出分类描述:
<?php
$category_description = category_description();
if ( !empty( $category_description ) ) echo $category_description ;
?> |
<?php
$category_description = category_description();
if ( !empty( $category_description ) ) echo $category_description ;
?>
输出RSS订阅:
<?php $category_id = get_query_var('cat') ; ?>
<a title="RSS 订阅该分类" href="<?php echo get_category_feed_link($category_id) ?>">RSS订阅</a> |
<?php $category_id = get_query_var('cat') ; ?>
<a title="RSS 订阅该分类" href="<?php echo get_category_feed_link($category_id) ?>">RSS订阅</a>
以上就是最核心的代码,具体的前端样式,就靠大家自己发挥了。
来源:
https://www.wpdaxue.com/echo-category-title-description-rss-feed.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33465.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57