0

Is there any function that can let me display older posts and post dates at the bottom of each post?The older posts must be in the same category. I searched on the internet but it seems that everyone just display one previous post only

Thank you very much

4

2 回答 2

0

您可以使用 wp 过滤器来实现这一点

// Return posts from the last 30 days:
function filter_where( $where = '' ) {
// posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}

add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );

或者

// Return posts for March 1 to March 15, 2010:
function filter_where( $where = '' ) {
// posts for March 1 to March 15, 2010
$where .= " AND post_date >= '2010-03-01' AND post_date < '2010-03-16'";
return $where;
}

add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );

有关更多信息,请参阅此http://codex.wordpress.org/Class_Reference/WP_Query

于 2012-10-15T01:44:45.213 回答
0

get_posts 函数允许您为帖子构建复杂的查询,您可以使用它来获取带有 order 和 category 参数的旧帖子。

于 2012-10-14T18:12:59.227 回答