首先:do not use query_posts
使用get_posts
或new WP_Query
相反
如果你想只显示浏览次数最多的帖子,你需要添加操作(例如wp)检查你是否在单个帖子页面上,并更新该帖子元views
(+1)。然后你可以做这样的事情
$topViewedPosts = new WP_Query( array(
\'post_type\' => \'post\',
\'meta_key\' => \'views\',
\'orderby\' => \'meta_value_num\', // sort by views
\'order\' => \'DESC\', // sort 3 - 2 - 1
\'posts_per_page\' => 5
) );
if( $topViewedPosts->have_posts() )
while( $topViewedPosts->have_posts() ) : $topViewedPosts->the_post();
// your content here
endwhile;
endif; wp_reset_postdata();
也许我误解了你在找什么。。尽量解释得比。。