Back WordPress

How to Display Most Popular Posts From a Specific Category in WordPress

WRITTEN BY ON 26 Jan 2011
19,600 VIEWS • SHARES
2 comments

There are many way to make visitor browsing more pages in your wordPress blog. One of them is showing most popular post on your sidebar or footer. This also help your visitors finding your best content. Most popular here I mean, most commented posts. But, what if the popular posts We want to display are from a single category only?

PHP

<?php
$args=array(
  'cat' => 3, // this is category ID
  'orderby' => 'comment_count',
  'order' => 'DESC',
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => 6, // how much post you want to display
  'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
	<ul>
	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
	<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
	<?php  endwhile; ?>
	</ul>
<?php }

wp_reset_query(); ?>

Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.

2 comments
Ahmed 12 years ago
How to display thumbnail to that posts, like you do in your sidebar?
Reply
Dimpy Thakur 10 years ago
Thanks its working for me
Reply