2012-12-14 33 views
0

如何在单个页面上显示我查看次数最多的帖子?WordPress的 - 如何获得浏览次数最多的帖子?

对于这一刻,我创建了一个新的模板页面(content-most-viewed.php),这个页面由get_template_part()调用;

在互联网上,我读过query_posts可以解决我的问题,但它似乎失败。

这是我的模板:

<?php query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC'); 
//query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC');?> 
<div class="post"> 
    <?php if (have_posts()) : ?> 
     <?php while (have_posts()) : the_post(); ?> 
      <div class="heading"> 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h2> 
      </div> 
      <?php the_content();?> 
      <div class="link-holder"><a href="/index.php">Retour</a></div> 
     <?php endwhile; ?> 
    <?php else : ?> 
     <div class="heading"> 
      <h2>Not Found</h2> 
     </div> 
     <p>Sorry, but you are looking for something that isn't here.</p> 
    <?php endif; ?> 
</div> 

但是,我只能得到最近的帖子,或 “未找到”(任何resutls)

在前进,谢谢!

回答

1

WordPress的本身并不跟踪帖子被视为有pluging是做到这一点的数量:WPPplugin repos
这些插件将建设功能做到这一点。

侧面说明
不使用query_posts它的坏的性能与特点。用WP_query代替。原因是坏:https://wordpress.stackexchange.com/a/50762/10911https://wordpress.stackexchange.com/a/50762/10911

+0

WordPress的热门职位&& WP_query没有似乎帮助我:/ $查询=新WP_Query( 'posts_per_page = 2&ORDER_BY =评论'); 我得到2个帖子,但是2个最后的帖子,而不是2个最多的评论的帖子... –

+0

那么参数字符串中的'order_by = comment_count'如何? – janw

+0

不,只有我的2个最后的帖子被渲染... Dudes,我认为我的CPU会跳过我的窗口:D –

相关问题