【发布时间】:2009-09-07 17:11:20
【问题描述】:
我只想在我的 wordpress 首页上显示最近 X 天的帖子。比方说,一周,所以 7 天。
告诉 wordpress 只选择循环中最后 X 天的帖子的正确方法是什么?
目前,我已经通过 hack 让它工作了,但它弄乱了分页。转到下一页不会选择正确的帖子。
//Hack found on the bottom of http://codex.wordpress.org/Template_Tags/query_posts
function filter_where($where = '') {
//posts in the last 7 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
if ( have_posts() ) : while ( have_posts() ) : the_post();
... and the usual
【问题讨论】: