
WordPress 黑客
类别提供了一种对 WordPress 内容进行排序的简单方法。然而,您可以对类别做更多的事情,以使您的网站对用户和搜索引擎更加友好。在本文中,我们将向您展示一些最受欢迎的 WordPress 类别黑客和插件。
类别提供了一种对 WordPress 内容进行排序的简单方法。但是,您可以对类别进行更多操作,以使您的网站对用户和搜索引擎更加友好。在本文中,我们将向您展示一些最受欢迎的 WordPress 类别黑客和插件。
1.类别RSS提要 (1. Category RSS Feeds)
您是否知道 WordPress 网站上的每个类别都有自己的 RSS 源?只需在类别 URL 末尾添加 feed,如下所示:
您是否知道 WordPress 网站上的每个类别都有自己的 RSS 源?只需将 feed 添加到类别 URL 的末尾,如下所示:
https://www.wpbeginner.com/category/news/feed/
https://www.wpbeginner.com/category/news/feed/
就这样,您可以在类别模板上添加此链接。别担心,我们将在本文后面向您展示如何创建类别模板。
就是这样,您可以将此链接添加到您的类别模板中。别担心,我们将在本文后面向您展示如何创建类别模板。
Another great benefit of category feeds is that you can allow your users to 订阅类别. This gives your users a chance to only subscribe topics that interest them.
类别供稿的另一个巨大好处是,您可以允许您的用户订阅类别 。 这使您的用户有机会只订阅他们感兴趣的主题。
2.具有RSS Feed链接的类别列表 (2. Category list with RSS Feed Links)
The default categories widget in WordPress does not allow you to display an RSS feed link next to category names. If you would like to display feed links next to category names, then add this code in your theme’s 函数.php file or a 特定于站点的 WordPress 插件.
WordPress中的默认类别窗口小部件不允许您在类别名称旁边显示RSS feed链接。 如果您想在类别名称旁边显示供稿链接,则将此代码添加到主题的函数.php文件或具体的于在网站的 WordPress 插件中 。
function wpb_categories_with_feed() {
$args = array(
'orderby' => 'name',
'feed' => 'RSS',
'echo' => false,
'title_li' => '',
);
$string .= '<ul>';
$string .= wp_list_categories($args);
$string .= '</ul>';
return $string;
}
// add shortcode
add_shortcode('categories-feed', 'wpb_categories_with_feed');
// Add filter to execute shortcodes in text widgets
add_filter('widget_text', 'do_shortcode');
You need to add [categories-feed]
shortcode inside a text widget to list categories with feed links next to them.
您需要在文本窗口小部件内添加[categories-feed]
简码,以列出类别及其旁边的feed链接。
3.在WordPress中添加类别图标 (3. Adding Category Icons in WordPress)
Images make the web more interesting. You can use images to make your category pages stand-out. To associate images with your categories you need to install and activate the Taxonomy Images plugin. Upon activation you need to visit 设置 » 图像分类 to enable images for categories.
图片使网络变得更加有趣。 您可以使用图像使类别页面突出。 要将图像与类别关联,您需要安装并激活“分类图像”插件。 激活后,您需要访问设置 » 对图像进行分类以启用类别图像。

To associate images with categories simply visit 帖子 » 类别 and click on the thumbnail icon to upload category images.
要将图像与类别相关联,只需访问帖子 » 类别 ,然后单击缩略图图标以上传类别图像。

See our guide on how to add WordPress 中的分类图像 for more details.
有关更多详细信息,请参见有关如何在 WordPress 中添加分类图像指南。
4.为页面启用类别 (4. Enable Categories for Pages)
By default categories are only available for posts in WordPress. However, you can associate them to any post type including pages. Simply install and activate 页面的帖子标签和类别 plugin. It works out of box and there are no settings for you to configure. Simply click on pages and you will see categories and tags under the pages menu. Take a look at our tutorial on how to 为 WordPress 页面添加类别和标签 for more information.
默认情况下,类别仅适用于WordPress中的帖子。 但是,您可以将它们与包括页面在内的任何帖子类型相关联。 只需安装并激活“页面标签”和“插件”即可。 它开箱即用,没有可供您配置的设置。 只需单击页面,您将在页面菜单下看到类别和标签。 查看有关如何将类别和标签添加到 WordPress 页面教程,以获取更多信息。

5.启用类别存档的便利贴 (5. Enable Sticky Posts for Category Archives)
In WordPress you can make posts sticky to feature them on your home page. To add sticky posts for your category pages, simply install and activate 类别置顶帖 plugin. Upon activation, the plugin adds a category sticky metabox on the post edit screen. See our tutorial on how to add WordPress 类别的置顶帖子 for detailed instructions.
在WordPress中,您可以使帖子发粘,使其在首页上显示。 要为您的类别页面添加便利贴,只需安装并激活类别便利贴插件。 激活后,该插件会在帖子编辑屏幕上添加一个类别粘性metabox。 有关详细说明,请参阅有关如何对于 WordPress 类别添加置顶帖教程。

6.在WordPress中创建类别模板 (6. Creating Category Templates in WordPress)
WordPress comes with a powerful theme engine. By default it looks for templates with specific names in your theme to display certain pages. For example, the category.php
template in a theme is used to display all category pages.
WordPress带有强大的主题引擎。 默认情况下,它将在主题中查找具有特定名称的模板以显示某些页面。 例如,主题中的category.php
模板用于显示所有类别页面。
Similarly, you can create templates for specific categories by naming the template with category name. For example, to create a template for movies category, you will name the template file category-movie.php
.
同样,您可以通过使用类别名称命名模板来为特定类别创建模板。 例如,要为电影类别创建模板,您将命名该模板文件category-movie.php
。
Use your theme’s category.php file as the starting point for your single category template and then make the changes you need. For more detailed instructions take a look at our tutorial on how to create WordPress 中的类别模板.
使用主题的category.php文件作为单个类别模板的起点,然后进行所需的更改。 有关更详细的说明,请参阅我们的有关如何在 WordPress 中创建类别模板教程。
7.从RSS Feed中排除特定类别 (7. Exclude Specific Categories from RSS Feed)
By default all your posts appear in your site’s RSS feed. If you would like to hide certain categories from site’s main RSS feed, then simply install and activate the 最终类别排除器 plugin. Upon activation, simply visit 设置 » 类别排除 to select categories you want to hide from your RSS feeds.
默认情况下,您的所有帖子都会显示在网站的RSS Feed中。 如果您想从站点的主要RSS feed中隐藏某些类别,则只需安装并激活最终类别排除器插件即可。 激活后,只需访问设置»类别排除,以选择要从RSS源中隐藏的类别。

8.显示特定类别的最新帖子 (8. Show Recent Posts from Specific Categories)
类别的主要用途是帮助您对内容进行排序并帮助您的用户轻松找到内容。如果用户发现特定类别中的帖子有趣,那么他们可能会阅读同一类别中的类似帖子。要显示某个类别中的最新帖子,请在您希望显示某个类别中的最新帖子的主题中使用此代码。
类别的主要目的是帮助您对内容进行排序并帮助用户轻松找到它。如果用户发现特定类别中的帖子有趣,他们可能会阅读同一类别中的类似帖子。要显示某个类别的最新帖子,请在主题中使用此代码,以便显示该类别的最新帖子。
$the_query = new WP_Query( 'category_name=news' );
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
将category_name 的值替换为您要使用的类别的名称。
将category_name 的值替换为您要使用的类别的名称。
9.将作者分配到特定类别 (9. Assign Author to Specific Categories)
When managing a multi-author WordPress site you may want to assign authors to only post into specific categories assigned to them. Simply install and activate the 限制作者发帖 plugin. Upon activation, go to 用户 and edit the user you want to assign a category. On the user edit screen you will see a 将作者帖子限制为某个类别 section, where you can select the category assigned to that particular user.
在管理多作者WordPress网站时,您可能希望分配作者仅发布到分配给他们的特定类别中。 只需安装并激活“ 限制作者发表”插件即可。 激活后,转到“ 用户”并编辑要分配类别的用户。 在用户编辑屏幕上,您将看到“ 限制作者发布到类别”部分,您可以在其中选择分配给该特定用户的类别。

10.在类别页面上显示摘录 (10. Show Excerpts on Category Pages)
我们建议用户在存档和类别页面上显示摘录。显示摘录只会减少页面加载时间,这有利于搜索引擎优化。除此之外,它还可以保护您免受网站上重复内容问题的影响。要用类别页面上的摘录替换完整内容,只需将此代码添加到主题的functions.php 文件或站点特定插件中即可。
我们建议用户在存档和类别页面上显示摘录。显示摘录只会减少页面加载时间,这对于 SEO 非常有用。除此之外,它还可以保护您免受网站上重复内容的影响。要将整个内容替换为类别页面上的摘录,只需将此代码添加到主题的functions.php 文件或特定于站点的插件中即可。
function my_excerpts($content = false) {
if(is_category()) :
global $post;
$content = $post->post_excerpt;
// If the post has explicitly set excerpt use that
if($content) :
$content = apply_filters('the_excerpt', $content);
// If no excerpt is set
else :
$content = $post->post_content;
$excerpt_length = 55;
$words = explode(' ', $content, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '...');
$content = implode(' ', $words);
endif;
$content = '<p>' . $content . '</p>';
endif;
endif;
return $content;
}
add_filter('the_content', 'my_excerpts');
You can also replace content with excerpt by editing your theme’s category.php file and replacing the_content with the_excerpt. For more instructions see this tutorial on how to 在 WordPress 主题中显示帖子摘录.
您还可以通过编辑主题的category.php文件并将the_content替换为the_excerpt,从而用摘录替换内容。 有关更多说明,请参阅本教程,了解如何在 WordPress 主题中显示帖子摘录 。
We hope this article helped you learn some new category hacks and plugins for WordPress. For more best practice tips, see our guide on 类别与标签(最佳实践).
我们希望本文能帮助您学习WordPress的一些新类别黑客和插件。 有关更多最佳做法的提示,请参见有关类别和标签指南(最佳实践) 。
If you liked this article, then please subscribe to our YouTube 频道 for WordPress video tutorials. You can also find us on 推特 and 谷歌+.
如果您喜欢这篇文章,请订阅我们的YouTube 频道 WordPress视频教程。 您也可以在推特和谷歌+上找到我们。
翻译自: https://www.wpbeginner.com/wp-tutorials/10-most-wanted-category-hacks-and-plugins-for-wordpress/
WordPress 黑客