我认为,如果您当月没有8篇帖子,最好只进行第二次查询,例如:
//get current date
$date = getdate();
//setup args
$args = array(
//basic stuff
\'posts_per_page\' => -1,
\'post_stutus\' => \'publish\',
//time parameters
\'year\' => $date[\'year\'],
\'month_num\' => $date[\'mon\']
);
//create WP_Query
$my_query = new WP_Query;
//execute first WP_Query
$posts = $my_query->query( $args );
//check first WP_Query, update if necessary
if( count( $posts ) < 8 ) {
//update args
unset( $args[\'year\'] );
unset( $args[\'mon\'] );
$args[\'posts_per_page\'] = 8;
//do query
$posts = $my_query->query( $args );
}
//do your loop and such
这是一些粗略的代码,我刚刚很快就完成了,但你明白了