我认为实现这一点的最佳方法是pre_get_posts
钩看看这个代码
function customize_query( $query ) {
$post = get_posts(array(
\'post_type\' => \'projects\',
\'taxonomy\' => \'featured\',
\'numberposts\' => 1
));
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( \'post_type\', \'projects\' );
$query->set( \'posts_per_page\', 6 );
if($post && !empty($post))
$query->set( \'post__not_in\', array($post[0]->ID) );
}
}
add_action( \'pre_get_posts\', \'customize_query\' );
然后在你的主页上
$post = get_posts(array(
\'post_type\' => \'projects\',
\'taxonomy\' => \'featured\',
\'numberposts\' => 1
));
// display the post just retrieved, it must be coming from cache
// we can use the global query since now it contains the 6 posts we want
while(have_posts()) :
the_post();
// display the post
endwhile;
您需要对其进行大量修改,但这可能会帮助您实现您想要的。在这里,分页应该正常工作,因为您刚刚修改了主页查询