您需要发送自定义查询以获取帖子列表。在本例中,我们使用一个自定义的post类型“project”和一个自定义的分类法“sphere”,并在当前sphere中得到一个下一个项目。在您的用例中,您可以将posts\\u per\\u page增加到4。
<?php
//remember the id and menu_order from current post
$id=get_the_ID();
global $haet_post_order;
$haet_post_order=$post->menu_order;
//There is only one sphere per project in this example
$custom_terms = get_the_terms($id, \'sphere\');
foreach ($custom_terms AS $term) {
$sphere=$term->slug;
}
function haet_filter_next_post( $where = \'\' ) {
global $haet_post_order;
$where .= \' AND menu_order>\'.$haet_post_order;
return $where;
}
add_filter( \'posts_where\', \'haet_filter_next_post\' );
$loop = new WP_Query( array( \'post_type\' => \'project\', \'posts_per_page\' => 1,\'orderby\' => \'menu_order\',\'order\' => \'ASC\',\'sphere\'=>$sphere ) );
remove_filter( \'posts_where\', \'haet_filter_next_post\' );
//if there is no next post use the first one
if( !$loop->have_posts() ){
$loop = new WP_Query( array( \'post_type\' => \'project\', \'posts_per_page\' => 1,\'orderby\' => \'menu_order\',\'order\' => \'ASC\',\'sphere\'=>$sphere ) );
}
while ( $loop->have_posts() ) : $loop->the_post();
// place you code here
?>
<?php endwhile; ?>
在while循环中,您可以使用
get_the_post_thumbnail(). 您可以在中找到更多描述行
this blog post