Support » Fixing WordPress » change home page sorting

  • For our home page I’ve been asked to change the ordering from most recent to order by most views. I have no idea how to do this. Can anyone point me in the right direction.

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi


    Forum Moderator

    WordPress doesn’t store Post or Page view, so the first thing you’ll need to do is find a plugin that will store this data for you.



    I found this – and it “seems” to work but not quite. I am getting posts with the larger views at the top but then I have posts with smaller views interspersed. You can see how it’s working here – And here’s the code I’m using. Notice there’s a section that shows the number of views in the code. It’s calling a function that returns get_post_meta($pid,’post_viewed_count’,true) which is what the args also order by, so I would think my number of views would decrease per row instead of going from 514 to 154 to 40 to 185.

    <?php $paged = intval(get_query_var('paged')); ?>
    <?php $paged = ($paged) ? $paged : 1; ?>
    $args = array(
       'orderby' => 'post_viewed_count',
       'order' => 'ASC',
    <?php query_posts($args); ?>
    <!-- ****** END ORDER BY VIEWS STUFF -->
    <?php while ( have_posts() ) : the_post(); ?>
              /* Include the Post-Format-specific template for the content.
               * If you want to overload this in a child theme then include a file
               * called content-___.php (where ___ is the Post Format name) and that will be used instead.
               */ ?>
              <div class="entry">
    		  <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    		  <div class="views"><?php echo user_post_visit_count($post->ID);?> Views</div><div class="categories"><?php the_category(', '); ?></div>
      <?php endwhile; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘change home page sorting’ is closed to new replies.