
Happy new year! To get started with this new year, what about displaying a list of the 10 most commented posts of 2008 to your readers? That’s obviously a great way to give a second life to your old posts.

Happy new year! To get started with this new year, what about displaying a list of the 10 most commented posts of 2008 to your readers? That’s obviously a great way to give a second life to your old posts.
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:
<h2>Most commented posts from 2008</h2>
<ul>
<?php
$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");
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title;
$commentcount = $topten->comment_count;
if ($commentcount != 0) {
?>
<li><a href="<?php echo get_permalink($postid); ?>"><?php echo $title ?></a></li>
<?php }
}
?>
</ul>
That's all! Hope you (and your readers!) like it ![]()
Best wishes to all of you and your families for 2009, have a happy and sucessfull year!
44 Responses
Should we use any plugin for this code? Coz I have a related plugin, but get an error with the code they give. So, I plan to add your code here, but what plugin should I use? Thanks
This is a great tip for the end of the year, but for me it made sense to include the number of comments each post in the list got.
This is an easy tweak, just change this line:
<a href="">To this:
<a href=""> ()
So is this what you are using on your Top Commentators sidebar? Seems that way..
Or at least your not showing 2008, and are now showing 2009 top commentators only. That’s cool, you should state that
Oops, my code got thrashed, that sucks.
All I changed was to echo the comment_count after the title is echoed…
Hmmm… never thought of this
I will give it a try on my personal blog.
It does not work in my blog !
Dommage.
=) Happy New Year!
IT WORKS!! thank you so much. For those who wants the plugin instead, go visit this site
http://mtdewvirus.com/code/wordpress-plugins/
Obviously I am doing something wrong. I put it in my sidebar, in a text/html box and (as you can expect) the code just shows up as text. So where ‘in my sidebar’ should I put it?
@ed: Paste the code in sidebar.php, not in a widget
I already suspected something like that. Thanks a bundle!!
Hi! I am trying to get a custom field from the postmeta table so that I can display an image next to the link title. Can you help me?
This is awesome. I’m using it now in my new template. Looks great. Hopefully I’ll get some comments to the older posts.
I’ve tried using this on a site in a page using Exec PHP but I get the following error:
Fatal error: Call to a member function get_results() on a non-object in /homepages/36/d222495733/htdocs/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 7
Can anyone suggest what might be wrong here?
How would I ensure that not only the most commented, but also the most recent feature in the results of the query. Adding and “ORDER BY post_date” is not working for me
Trackbacks: