wordpress排除分类_如何从WordPress RSS Feed中排除特定类别

wordpress排除分类

Do you want to exclude specific categories from RSS feed on your WordPress site? Many site owners use some categories for content that they don’t want to appear in the RSS feed of their site. In this article, we will show you how to exclude specific categories from WordPress RSS feed.

您是否要从WordPress网站上的RSS提要中排除特定类别? 许多网站所有者使用某些类别的内容,使其不想出现在其网站的RSS feed中。 在本文中,我们将向您展示如何从WordPress RSS feed中排除特定类别。

exclude category exclude specific category RSS feed feed
方法1:使用插件从WordPress RSS Feed中排除特定类别 (Method 1: Exclude Specific Categories from WordPress RSS Feed Using Plugin)

First thing you need to do is install and activate the Ultimate Category Excluder plugin. For more details, see our step by step guide on how to install a WordPress plugin.

您需要做的第一件事是安装并激活Ultimate Category Excluder插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation you need to visit Settings » Category Exclusion to configure plugin settings.

激活后,您需要访问设置»类别排除以配置插件设置。

Category excluder

The settings page will display all categories on your WordPress blog with options to hide them from front page, RSS feeds, archive pages, and search results.

设置页面将显示WordPress博客上的所有类别,并提供选项以将其从首页, RSS feed ,存档页面和搜索结果中隐藏。

Simply select the exclude from feed box next to the categories that you want to exclude from your RSS feed.

只需选择要从RSS feed中排除的类别旁边的“从feed中排除”框。

Don’t forget to click on update button to save your settings.

不要忘记单击更新按钮以保存您的设置。

That’s all, posts filed under your selected categories will disappear from your WordPress RSS feed.

仅此而已,在您选择的类别下提交的帖子将从您的WordPress RSS feed中消失。

方法2:从WordPress RSS Feed中手动排除特定类别 (Method 2: Manually Exclude Specific Categories from WordPress RSS Feed)

This method requires you to paste code in your WordPress files. You can use this method if you are comfortable with pasting code snippets from web into WordPress.

此方法要求您将代码粘贴到WordPress文件中。 如果您愿意将来自Web的代码片段粘贴到WordPress中,则可以使用此方法。

You need to add this code to your theme’s functions.php file or a site-specific plugin.

您需要将此代码添加到主题的functions.php文件或特定站点的插件中


function exclude_category($query) {
	if ( $query->is_feed ) {
		$query->set('cat', '-5, -2, -3');
	}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

This code simply excludes categories that match the given IDs. Simply replace the category IDs in the code with the IDs of categories that you want to exclude.

此代码仅排除与给定ID匹配的类别。 只需将代码中的类别ID替换为您要排除的类别ID。

See our guide on how to find category IDs in WordPress.

请参阅我们的指南, 了解如何在WordPress中查找类别ID

If you just want to exclude a single category, then change the code like this:

如果您只想排除一个类别,则可以这样更改代码:


function exclude_category($query) {
	if ( $query->is_feed ) {
		$query->set('cat', '-15');
	}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

Replace -15 with the ID of category that you want to exclude from RSS feed.

将-15替换为要从RSS feed中排除的类别ID。

We hope this article helped you learn how to exclude specific categories from WordPress RSS feed. You may also want to see our list of 10 most wanted category hacks and plugins for WordPress.

我们希望本文能帮助您学习如何从WordPress RSS feed中排除特定类别。 您可能还希望查看我们的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-exclude-specific-categories-from-wordpress-rss-feed/

wordpress排除分类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值