【问题标题】:Wordpress post category out of the loop but in the rss feedWordpress 帖子类别不在循环中,但在 rss 提要中
【发布时间】:2014-06-30 18:25:20
【问题描述】:

在我的网站中,使用 wordpress 完成,我有这个功能可以排除某些类别出现在主页中:

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

但它们也被排除在 RSS 提要之外。有一种方法可以将它们从主页中排除,但将它们包含在 RSS Feed 中?

我使用通过这些函数创建的自定义 RSS

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

this 是 rss-ppfeed.php 文件

谢谢

【问题讨论】:

    标签: wordpress rss


    【解决方案1】:

    您需要从 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');
    

    编辑

    在行号 '5' 之前添加这个 IE 在 $postCount = 10 的行之前; , 在 rss-ppfeed.php 中

    remove_filter('pre_get_posts','excludeCat');

    【讨论】:

    • 这很奇怪,如果您使用的是免费主题,请您命名它吗?
    • 它不是免费的,它叫Mediablog,我的网站是primapaginaonline.it
    • 只是为了确定,你已经把代码放在你的主题functions.php中了,对吧?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多