Code Snippet > PHP
How to Display Most Popular Posts From a Specific Category in WordPress
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(); ?>
Leave a comment
Have something to say? Drop a comment! No HTML tags are allowed in the comment textfield.





















0 comments