Posted By

selfmadepsyche on 02/09/09


Tagged

wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

nerdfiles
Bluewall


Display the most commented posts


 / Published in: PHP
 

URL: http://www.wprecipes.com/how-to-display-the-most-commented-posts-of-2008

To display a list of your 10 most commented posts from 2008, simply paste the following code on your blog sidebar, or anywhere on your theme.

  1. <h2>Most commented posts from 2008</h2>
  2. <ul>
  3. <?php
  4. $result = $wpdb->get_results("SELECT comment_count,ID,post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN '2008-01-01' AND '2008-12-31' ORDER BY comment_count DESC LIMIT 0 , 10");
  5.  
  6. foreach ($result as $topten) {
  7. $postid = $topten->ID;
  8. $title = $topten->post_title;
  9. $commentcount = $topten->comment_count;
  10. if ($commentcount != 0) {
  11. ?>
  12. <li><a href="<?php echo get_permalink($postid); ?>"><?php echo $title ?></a></li>
  13. <?php }
  14. }
  15. ?>
  16. </ul>

Report this snippet  

You need to login to post a comment.