How to Display Most Popular Posts from a Specific Category


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $args=array(
  3. 'cat' => 3,
  4. 'orderby' => 'comment_count',
  5. 'order' => 'DESC',
  6. 'post_type' => 'post',
  7. 'post_status' => 'publish',
  8. 'posts_per_page' => 6,
  9. 'caller_get_posts'=> 1
  10. );
  11. $my_query = null;
  12. $my_query = new WP_Query($args);
  13. if( $my_query->have_posts() ) { ?>
  14. <ul>
  15. <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
  16. <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  17. <?php endwhile; ?>
  18. </ul>
  19. <?php }
  20.  
  21. wp_reset_query(); ?>
  22.  
  23.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.