Skip to content

Instantly share code, notes, and snippets.

@artlung
Created March 16, 2010 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlung/334180 to your computer and use it in GitHub Desktop.
Save artlung/334180 to your computer and use it in GitHub Desktop.
<?php
// this goes in functions.php in your theme. Then you can use shortcode [most_commented] in posts and pages
// to get the top 150 posts
function mostCommented() {
echo '<p>';
$posts_per_page = 150;
query_posts('orderby=comment_count&posts_per_page='.$posts_per_page.'&order=DESC');
if ( have_posts() ) : while ( have_posts() ) : the_post();
echo '<a href="';
the_permalink();
echo '" rel="bookmark" title="';
the_title_attribute('','',false);
echo '">';
the_title();
echo '</a>';
echo ' <span title="Number of comments: ';
comments_number('0','1','%');
echo '">(';
comments_number('0','1','%');
echo ')</span> <br />';
echo "\n";
endwhile;
else :
echo '<p>Sorry, no posts were found.</p>';
endif;
echo '</p>';
// reset the query so when I use it it doesn't
// cause posts to be displayed
query_posts('tag=NOTAREALTAG');
return $out;
}
add_shortcode('most_commented', 'mostCommented');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment