Skip to content

Instantly share code, notes, and snippets.

@palpalani
Created September 27, 2012 05:33
Show Gist options
  • Save palpalani/3792324 to your computer and use it in GitHub Desktop.
Save palpalani/3792324 to your computer and use it in GitHub Desktop.
WordPress: List popular posts by comment count
<?php
/*
* List popular posts by comment count
* This function used for Genesis custom theme, May be work with any theme.
*/
function m3_popular_posts(){
$args = array(
'no_found_rows' => 1,
'post_status' => 'publish',
'orderby' => 'comment_count',
'posts_per_page' => 5
);
$popular_posts = new WP_Query( $args );
/*
echo "Last wp_popular_posts-Query: {$popular_posts->request}";
*/
while ( $popular_posts->have_posts() ) : $popular_posts->the_post();
echo '<div class="post m3-posts">';
if ( has_post_thumbnail() ){
printf('<a href="%s" title="%s" rel="bookmark" class="post-thumbnail alignleft">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), get_the_title() );
}
printf('<h2><a href="%s">%s</a></h2><p class="byline post-info"><span class="date published time">%s</span></p>', get_permalink(), get_the_title(), get_the_time(get_option('date_format')));
echo '</div><!--end m3-posts -->';
endwhile;
wp_reset_query();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment