Skip to content

Instantly share code, notes, and snippets.

@UmeshSingla
Created May 29, 2013 05:33
Show Gist options
  • Save UmeshSingla/5668176 to your computer and use it in GitHub Desktop.
Save UmeshSingla/5668176 to your computer and use it in GitHub Desktop.
Wordpress Popular Post Sorted by Comment Count
<?php
/* Add this where you want to display popular post sorted by comment count */
$args = array( 'orderby' => 'comment_count', 'numberposts' => $rtp_post_count, 'post_status' => 'publish' );
$posts = get_posts($args); ?>
<!-- Output Markup -->
<ul class="rtp-most-popular-wrapper"><?php
$count=1;
for($i=0; $i<sizeof($posts); $i++){?>
<li>
<a href="<?php echo get_permalink($posts[$i]->ID); ?>" title="<?php echo $posts[$i]->post_title; ?>" target="_blank"><?php echo $count.'. '.$posts[$i]->post_title; ?></a>
</li><?php
$count++;
}?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment