Show posts with most views with WP_Query
-
Hi,
I was wondering how I can show the posts with the most views. I already figured out the loop but i’m not sure what I’m suppose to use as the parameter/variable for Post Views Counter.
Here is the code I have:
<?php $most_popular_query = new WP_Query( array( 'category_name' => 'competitive', 'posts_per_page' => 2 ) ); while ( $most_popular_query->have_posts() ) : $most_popular_query->the_post(); ?> <article class="post<?php if( $most_popular_query->current_post == $most_popular_query->post_count-1 ) echo ' last'; ?>"> <div class="thumb"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'frontpage-most-popular-thumb' ); ?></a></div> <div class="cat"><?php the_category(', ') ?></div> <h3><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php echo(get_the_title()); ?></a></h3> </article><!-- /.post --> <?php endwhile; // Reset Query wp_reset_query() ?>
Thanks!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Show posts with most views with WP_Query’ is closed to new replies.