WordPress 101 Guide | Make a Query to Get the Most Popular Post by Comment Count in WordPress

//WordPress 101 Guide | Make a Query to Get the Most Popular Post by Comment Count in WordPress

WordPress 101 Guide | Make a Query to Get the Most Popular Post by Comment Count in WordPress

This one is very simple. For those of you that want to automatically include it in your themes, you can query by comment count using get_posts and running a foreach loop to get the contents. Very simple procedure.

Code below will output the most popular post by comment count.

[php]
<? $args = array(‘posts_per_page’ => 5, ‘orderby’ => ‘comment_count’);
global $post;
$popular = get_posts($args);
foreach($popular as $post) {
setup_postdata($post); ?>

<a href="<?php the_permalink(); ?>"><?php the_title();?></a>

<?php endforeach;?>
[/php]

Give it a try on your template.

By | 2012-04-03T11:28:25+00:00 April 3rd, 2012|Categories: Wordpress 101 Guide|Tags: , , , |0 Comments

About the Author:

Leave A Comment