简体   繁体   English

Wordpress发布类别不在循环中,但在RSS提要中

[英]Wordpress post category out of the loop but in the rss feed

in my website, done with wordpress, I have this function for excluding some category from appearing in homepage: 在我的网站上,通过使用wordpress,我具有此功能,可以将某些类别排除在首页之外:

function excludeCat($query) {
if ( $query->is_home ) {
$query->set('cat', '-14, -64, -68, -22, -15');
}
return $query;
}
add_filter('pre_get_posts', 'excludeCat');

But they are excluded also from the RSS feed. 但是它们也从RSS feed中排除。 There is a way to exclude them from the homepage but include them in RSS Feed? 有一种方法可以将其从首页中排除,但将其包括在RSS Feed中?

I use custom RSS created with these functions 我使用通过这些功能创建的自定义RSS

function customRSS(){
add_feed('ppfeed', 'customRSSFunc');
}
function customRSSFunc(){
get_template_part('rss', 'ppfeed');
}

And this is the rss-ppfeed.php file 是rss-ppfeed.php文件

Thanks 谢谢

You need to exclude the feed ( edit page templates also) page from your if condition 您需要从if条件中排除供稿(也需要编辑页面模板)页面

function excludeCat($query)
{
    if ($query->is_home() && !is_page()) {
        $query->set('cat', '-14, -64, -68, -22, -15');
    }
    return $query;
}

add_filter('pre_get_posts', 'excludeCat');

Edit 编辑

Add this before the line number '5' IE before the line with $postCount = 10; 在$ postCount = 10的行之前,在IE的行号“ 5”之前添加IE; , in rss-ppfeed.php ,在rss-ppfeed.php中

remove_filter('pre_get_posts','excludeCat');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM