我最终不得不从另一个角度重新考虑这个问题。我不必从主要Feed中排除帖子,而必须为每个类别创建独特的Feed。这使得这些提要独立于主要Feed,并且不会受到WP Hide Posts插件的影响。
我所做的就是将这个文件放到我的主题文件夹中,然后用分配给它的模板创建空白页。在顶部,我负责处理每个创建的页面并将其分配给相应的类别。
<?php
/*
Template Name: Custom feeds
*/
$numposts = 10; // number of posts in feed
if (is_page('custom-feed-1')) {
$posts = query_posts('showposts='.$numposts.'&cat=1');
} elseif (is_page('custom-feed-2')) {
$posts = query_posts('showposts='.$numposts.'&cat=2');
} elseif (is_page('custom-feed-3')) {
$posts = query_posts('showposts='.$numposts.'&cat=3');
}
$more = 1;
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title><?php bloginfo_rss('name'); wp_title_rss(); ?> - Article Feed</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss("description") ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<?php the_generator('rss2'); ?>
<language>en-US</language>
<sy:updatePeriod><?php echo apply_filters('rss_update_period', 'hourly'); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters('rss_update_frequency', '1'); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php while(have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss(); ?></title>
<link><?php the_permalink_rss(); ?></link>
<comments><?php comments_link(); ?></comments>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<dc:creator><?php the_author(); ?></dc:creator>
<?php the_category_rss(); ?>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if (get_option('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php if (strlen($post->post_content) > 0) : ?>
<content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<?php endif; ?>
<?php endif; ?>
<?php do_action('rss2_item'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>
此外,我不希望要求打好这个模板,我在网上找到的一段时间回来,并修改了一点,我只是不记得我碰到它哪里传来。
这是我的问题的一部分。当你在functions.php中排除它时,整个网站都会发生变化,因为WP基本上将RSS源视为一个设置,而不是区分类别源或任何内容。所以我会排除一个类别,然后将无法访问该类别的饲料。 – jbwharris