wordpress描述调用_如何在WordPress中显示类别描述

wordpress描述调用

Do you want to display category descriptions on your WordPress site? Categories allow you to easily sort content on your website. They also help users easily find content and are good for SEO. In this article, we will show you how to easily display category descriptions in WordPress.

您是否要在WordPress网站上显示类别描述? 类别使您可以轻松地对网站上的内容进行排序。 它们还可以帮助用户轻松查找内容,并且对SEO很有帮助。 在本文中,我们将向您展示如何轻松地在WordPress中显示类别描述。

How to display category description in WordPress
在WordPress中添加类别描述 (Adding Category Descriptions in WordPress)

WordPress comes with two built-in taxonomies called categories and tags. These taxonomies allow you to easily sort your content into different topics.

WordPress带有两个内置的分类法,称为分类和标签 。 这些分类法使您可以轻松地将内容分类为不同的主题。

When used correctly, categories and tags can also be very helpful in improving your WordPress SEO.

如果使用得当,类别和标签也将对改善WordPress SEO很有帮助。

WordPress allows you to add descriptions for your categories. However, many users don’t notice it because they create categories when writing a post which doesn’t let them add description.

WordPress允许您为类别添加描述。 但是,许多用户没有注意到它,因为他们在写帖子时创建类别,而这些帖子不能让他们添加描述。

Here is how to easily add description to your categories.

这是在类别中轻松添加说明的方法。

Head over to Posts » Categories page. If you are creating a new category, then you can simply enter category name and description here and then click on ‘Add new category’ button.

转到帖子»类别页面。 如果要创建新类别,则只需在此处输入类别名称和描述,然后单击“添加新类别”按钮。

Add category description

If you want to add description to an existing category, then you need to click on the ‘Edit’ link below that category.

如果要向现有类别添加说明,则需要单击该类别下方的“编辑”链接。

This will take you to category edit screen where you can add description for your category.

这将带您进入类别编辑屏幕,您可以在其中添加类别描述。

Editing a category to add description

Don’t forget to click on the ‘Update’ button to save your changes.

不要忘记点击“更新”按钮来保存您的更改。

Repeat the process to add descriptions to all your categories. You can use the same method to add descriptions for tags as well.

重复此过程以将描述添加到所有类别。 您也可以使用相同的方法来添加标签的描述。

在类别存档页面上显示类别说明 (Display Category Description on Category Archive Page)

Most WordPress themes will automatically display the category description on the category archive pages.

大多数WordPress主题都会在类别存档页面上自动显示类别描述。

Category description shown on category archive page in WordPress

However if your theme does not display category description on archive pages, then you will need to edit your theme files.

但是,如果您的主题未在存档页面上显示类别描述,那么您将需要编辑主题文件。

Connect to your WordPress site using an FTP client and then go to /wp-content/themes/your-current-theme/ folder.

使用FTP客户端连接到WordPress网站,然后转到/ wp-content / themes / your-current-theme /文件夹。

Now you will need to locate and edit category.php file. If your theme doesn’t have category.php file, then you will need to edit archive.php file.

现在,您将需要查找和编辑category.php文件。 如果您的主题没有category.php文件,则需要编辑archive.php文件。

Copy and paste this code where you would like the category description to be displayed.

将此代码复制并粘贴到您希望显示类别描述的位置。


<?php 
the_archive_description( '<div class="taxonomy-description">', '</div>' ); 
?>

You can now save your changes and upload the file back to your website.

您现在可以保存所做的更改,并将文件上传回您的网站。

After that, you can visit the category archive page on your website to see the description in action.

之后,您可以访问网站上的类别存档页面以查看实际的描述。

在WordPress主题中显示类别描述 (Display Category Description in WordPress Theme)

If you want to display the category description in other parts of your website, then you can also use the category_description template tag:

如果要在网站的其他部分显示类别描述,则还可以使用category_description模板标记:


<?php echo category_description(3); ?>

Don’t forget to replace 3 with your own category ID.

不要忘记用您自己的类别ID替换3。

If you want to display category description inside a single post, then you can use this code.

如果要在单个帖子中显示类别描述,则可以使用此代码。


$catID = get_the_category();
echo category_description( $catID[0] ); 

This code simply gets all categories for the current post and then outputs the category description of the first category.

此代码仅获取当前帖子的所有类别,然后输出第一个类别的类别描述。

If you would like to list all your WordPress categories with a description in list format, then you can add this code in your theme’s functions.php file:

如果您想以列表格式列出所有WordPress类别及其描述,则可以将此代码添加到主题的functions.php文件中:


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');

This code creates a shortcode which displays all your categories and their descriptions in a plain list.

这段代码创建了一个简码 ,以简明的列表显示所有类别及其描述。

You can now use [wpb_categories] in your posts and pages. To use this shortcode inside a text widget, you will need to enable shortcodes for widgets.

现在,您可以在帖子和页面中使用[wpb_categories] 。 要在文本窗口小部件中使用此短代码,您将需要为窗口小部件启用短代码

List WordPress categories with description

We hope this article helped you learn how to add and display category descriptions in WordPress. You may also want to see our list of most wanted category hacks and plugins for WordPress.

我们希望本文能帮助您学习如何在WordPress中添加和显示类别描述。 您可能还希望查看我们的WordPress最受欢迎类别的黑客和插件列表。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-display-category-descriptions-in-wordpress/

wordpress描述调用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值