如何完全禁用WordPress生成的RSS提要中的提要项目限制?我知道您可以修改限制,但我想通过编程完全禁用限制。
如何输出无限的RSS提要项目
3 个回复
SO网友:Hadi77
现在,作为wp-includes/feed-rss2.php 但是,没有任何方法可以通过使用特定于提要页的挂钩或过滤器来实现这一点,因此您必须:
手动编辑此文件(每次更新后都会断开此文件)
function feed_unlimited_posts( $query ){
if(is_feed())
$query->set( \'posts_per_page\', -1 );
return $vars;
}
add_action( \'pre_get_posts\', \'feed_unlimited_posts\' );
Please Note: 我还没有对这段代码进行测试,如果你做了并且成功了,请建议编辑。谢谢SO网友:Adrian
使用pre_get_posts
更改查询。
对于需要设置的提要posts_per_rss
."E-1英寸;因为unlimited对我不起作用,所以我只使用了大量的数字(如果我看得对的话,提要总是分页的)。
add_action( \'pre_get_posts\', \'custom_feed_set_posts_per_rss\' );
function custom_feed_set_posts_per_rss( $query ){
if($query->is_feed){
$query->set( \'posts_per_rss\', 1000 );
}
}
SO网友:Shreyo Gi
这是一个以模板样式生成RSS的示例。
<?php
/*
Template Name: Article Feed
*/
$numposts = 10; // number of posts in feed
$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/"
<?php do_action(\'rss2_ns\'); ?>
>
<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><?php echo get_option(\'rss_language\'); ?></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; ?>
<wfw:commentRss><?php echo get_post_comments_feed_link(); ?></wfw:commentRss>
<slash:comments><?php echo get_comments_number(); ?></slash:comments>
<?php rss_enclosure(); ?>
<?php do_action(\'rss2_item\'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>
在该准则中,一个特定类别的职位数量限制为10个。我希望你需要努力工作来满足你的需要。如果您还生成自己的查询(可能使用wp\\u query),然后使用返回的数组填充RSS的字段
供参考:Digging WP\'s article on customizing RSS feeds
P、 S:代码未测试。
结束