简体   繁体   English

Wordpress-如何获得最多浏览的帖子?

[英]Wordpress - How to get the most viewed posts?

How can I display my most viewed posts on a single page ? 如何在单个页面上显示观看次数最多的帖子?

For this moment, i've create a new template page (content-most-viewed.php) wich is called by get_template_part(); 目前,我已经创建了一个新的模板页面(content-most-viewed.php),由get_template_part()调用。

On Internet, i've read that query_posts could solve my problem, but it seems to fail. 在Internet上,我已阅读到query_posts可以解决我的问题,但似乎失败了。

This is my template : 这是我的模板:

<?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>

But, I can only get recent posts, or "Not Found" (any resutls) 但是,我只能得到最近的帖子,或“未找到”(任何结果)

In advance, thanks ! 预先,谢谢!

WordPress by itself does not keep track of the number a post is viewed there are pluging that do this: WPP , plugin repos WordPress本身并不跟踪查看帖子的数量,有插件可以执行此操作: WPP插件存储库
These plugins will have build in functions to do this. 这些插件将具有内置功能来执行此操作。

side note 边注
don't use query_posts its bad for preformance. 不要使用query_posts对性能不利。 use WP_query in stead. WP_query使用WP_query reasons why it is bad: https://wordpress.stackexchange.com/a/50762/10911 , https://wordpress.stackexchange.com/a/50762/10911 不好的原因: https : //wordpress.stackexchange.com/a/50762/10911,https : //wordpress.stackexchange.com/a/50762/10911

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM