如果您要向现有类别添加说明,则需要点击该类别下方的“修改”链接。
这将带您进入类别编辑屏幕,您可以在其中添加类别的说明。
不要忘记单击“更新”按钮以保存更改。
重复此过程以向所有类别添加说明。您也可以使用相同的方法添加标记的描述。
但是,如果主题未在存档页面上显示类别说明,则需要编辑主题文件。
使用FTP客户端连接到WordPress网站,然后转到/ wp-content / themes / your-current-theme /文件夹。
现在,您需要找到并编辑category.php文件。如果您的主题没有category.php文件,那么您将需要编辑archive.php文件。
将此代码复制并粘贴到您希望显示类别说明的位置。
|
1
2
3 |
<?php the_archive_description( '<div class="taxonomy-description">', '</div>' ); ?> |
category_description模板标记:
|
1 |
<?php echo category_description(3); ?> |
|
1
2 |
$catID = get_the_category();echo category_description( $catID[0] ); |
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14 |
function wpb_catlist_desc() { $string = '<ul>';$catlist = get_terms( 'category' );if ( ! empty( $catlist ) ) { foreach ( $catlist as $key => $item ) { $string .= '<li>'. $item->name . '<br />'; $string .= '<em>'. $item->description . '</em> </li>'; }}$string .= '</ul>';return $string; }add_shortcode('wpb_categories', 'wpb_catlist_desc'); |
[wpb_categories]在帖子和页面中使用。要在文本小部件中使用此短代码,您需要为小部件启用短代码。
我们希望本文能帮助您学习如何在WordPress中添加和显示类别描述。您可能还想查看我们的WordPress最想要的类别黑客和插件列表。