A few days ago i had to make a minor change to my friend’s site, he wanted the latest comments to be right on top instead of the usual at the bottom of a page, so I had to re-arrange how the comments appeared and if for some reason you need this function all you have to do is a minor edit of /wp-includes/comment-template.php.
Original Code:
// TODO: Use API instead of SELECTs.
if ( $user_ID) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND (comment_approved = '1' OR ( user_id = '$user_ID' AND comment_approved = '0' ) ) ORDER BY comment_date");
} else if ( empty($comment_author) ) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date");
}
Amazingly enough all you have to do is add a four letter word… DESC :
// TODO: Use API instead of SELECTs.
if ( empty($comment_author) ) {
$comments = $wpdb->get_results(”SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND comment_approved = ‘1′ ORDER BY comment_date DESC“);
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results(”SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND ( comment_approved = ‘1′ OR ( comment_author = ‘$author_db’ AND comment_author_email = ‘$email_db’ AND comment_approved = ‘0′ ) ) ORDER BY comment_date DESC“);
}
That’s it!
UPDATE: I fired up my Dreamwever and can confirm that you’ll find the code in just about line 290
If you enjoyed this post, make sure you subscribe to my RSS feed!
Related posts:




March 29th, 2008 at 9:28 pm
Remember this change bevor you do a wordpress update, because it is a system file which usualy gets overwritten in a full update.
March 30th, 2008 at 12:59 am
Hello,
i have tried to apply it but it does not work on my existing posts… i am using Wp 2.3.3…
April 4th, 2008 at 1:43 pm
If you don’t want to edit the core files, then you can use my Plugin to do it. http://sudarmuthu.com/wordpress/reverse-comments
All you have to do is to drop my Plugin the Plugin directory and then activate it, you don’t need to edit the theme or any of the core files.
April 10th, 2008 at 12:35 pm
hi moses, you can get the same result by using array_reverse php function to the $comments array before comment loop in comments.php file.
April 24th, 2009 at 4:36 pm
This is a good way to accomplish the task. I usually us wp ajaxed plugin to accomplish this task but, I will use this now since I will cut down on the load time without that plugin
Thanks a bunch.
May 12th, 2009 at 5:51 am
This is good way to complete our task easily…
Thanks for it but at some point it conflict otherwise good try…