
hexo添加RSS订阅
Recently on WPBeginner, we wrote an article about 如何允许用户订阅 WordPress 中的类别. We briefly mentioned that WordPress offers RSS subscription for all taxonomies: categories, tags, and 自定义分类法. In this article, we will show you how to add RSS订阅 for tags and custom taxonomy archives.
最近在WPBeginner上,我们写了一篇关于如何允许用户订阅 WordPress 中的类别的文章。 我们简要地提到了WordPress为所有分类法提供RSS订阅:类别,标签和自定义分类法 。 在本文中,我们将向您展示如何为标签和自定义分类档案添加RSS订阅 。
Similar to categories, each custom taxonomy has it’s own feed URL. All you have to do is add /feed/
at the end of the URL. For example:
与类别相似,每个自定义分类法都有其自己的供稿URL。 您所要做的就是在URL末尾添加/feed/
。 例如:
https://www.wpbeginner.com/section/wp-themes/feed/
https://www.wpbeginner.com/section/wp-themes/feed/
让我们看看如何在标签和自定义分类存档上添加 RSS 订阅链接。
我们来看看如何在标签和自定义类别存档中添加RSS订阅链接。
在标签档案上添加RSS订阅链接 (Adding RSS Subscription Link on Tag Archives)
First thing you need to do is go inside your theme’s folder and find the file called tag.php. If you don’t see tag.php, then look for archive.php. If you don’t see either of those, then there is a strong chance that you are using a WordPress 主题框架, and this article will not be as helpful for you.
您需要做的第一件事是进入主题文件夹,然后找到名为tag.php的文件。 如果看不到tag.php,请寻找archive.php。 如果您没有看到任何一个,则很有可能您正在使用WordPress 主题框架 ,并且本文对您没有帮助。
现在,如果您的主题有 tag.php 文件,则只需在循环之前添加以下代码即可。
现在,如果您的主题有 tag.php 文件,则只需在循环之前添加以下代码即可。
$tag_id = get_query_var('tag_id');
echo '<div class="tag-feed"><p><a href="' . get_tag_feed_link( $tag_id) . '" title="Subscribe to this tag" rel="nofollow">Subscribe</a></p></div>';
?>
如果您没有 tag.php 文件,但有 archive.php 文件,则创建一个名为 tag.php 的新文件,并将 archive.php 中的所有代码粘贴到其中。完成后,将上面的代码粘贴到其中。
如果您没有 tag.php 文件,但有 archive.php 文件,则创建一个名为 tag.php 的新文件,并将 archive.php 中的所有代码粘贴到其中。完成后,将上面的代码粘贴到其中。
在上面的代码中,我们首先检索标签 ID,然后使用它来获取标签提要链接。要添加图像图标,只需将订阅文本替换为图像标签,就像我们对类别所做的那样。这是它在我们的测试网站上的样子。
在上面的代码中,我们首先获取标签ID,然后使用它来获取标签提要链接。要添加图像图标,只需用图像标签替换订阅文本,就像我们对类别所做的那样。这是它在我们的测试站点上的外观。

我们可以对自定义分类档案做同样的事情。
我们可以对自定义类别配置文件执行相同的操作。
在自定义分类档案中添加RSS订阅链接 (Adding RSS Subscription Link on Custom Taxonomy Archives)
WordPress allows you to add custom taxonomies to go beyond the default categories and tags (Tutorial: 如何创建自定义分类法). The process of adding a RSS subscription link on custom taxonomy archives is very similar.
WordPress允许您添加自定义分类法,以超越默认类别和标签(教程: 如何创建自定义分类法 )。 在自定义分类档案上添加RSS订阅链接的过程非常相似。
Go inside your theme’s folder and look for a file named as taxonomy-{taxonomy-name}.php
(for ex: taxonomy-topics.php
if your custom taxonomy is called topics). If you don’t have a custom taxonomy template, then create a new file. Copy and paste the content of your archive.php file into this new file. Once you are done, then paste the following code above the loop:
进入主题文件夹,然后找到一个名为taxonomy-{taxonomy-name}.php
(例如:如果您的自定义分类法称为taxonomy-topics.php
则为taxonomy-topics.php
)。 如果您没有自定义分类模板,则创建一个新文件。 将您的archive.php文件的内容复制并粘贴到此新文件中。 完成后,将以下代码粘贴到循环上方:
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo '<div class="topic-feed"><p><a href="' . get_term_feed_link($term->term_id, topics, $feed) . '" title="Subscribe to this topic" rel="nofollow">Subscribe</a></p></div>';
?>
我们希望您发现这篇文章对于将 RSS 源链接添加到您的标签和自定义分类存档页面很有用。如果您有任何问题或建议,请在下面发表评论告诉我们。
我们希望您发现本文对于将 RSS 源链接添加到标签和自定义类别存档页面很有用。如果您有任何问题或建议,请在下面发表评论告诉我们。
hexo添加RSS订阅