WordPress comment sort order

Webmasters! Check out these money makers!!!!

Banned from Google? Check out this post!

Sort comment display order (ascending) ASC or (descending) DESC in WordPress 2.6.

I found this information on the web that was written about a year ago. Kudos to whomever hypOr is!

After searching through wp-includes/comment-template.php I found where to implement the mod. Works with my WP v2.6 no problem. However, when it comes time to upgrade your 2.6, you will have to do this again provided the future versions don’t change this one particular function. Future versions may even include this in the admin area. I hope. ;-)

Around line 642 in wp-includes/comment-template.php you need to add:

, $order = 'DESC'

after:
$file = '/comments.php'

Example:

function comments_template( $file = '/comments.php', $order = 'DESC' )

No mods to these areas:

{
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;

if ( ! (is_single() || is_page() || $withcomments) )
return;

$req = get_option('require_name_email');
$commenter = wp_get_current_commenter();
extract($commenter, EXTR_SKIP);

/** @todo Use API instead of SELECTs. */
if ( $user_ID) {

Then on ~lines 654, 656 and 658 add:

$order

after:
ORDER BY comment_date

Example:

$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )

ORDER BY comment_date $order",

$post->ID, $user_ID));
} else if ( empty($comment_author) ) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'

ORDER BY comment_date $order",

$post->ID));
} else {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) )

ORDER BY comment_date $order",

$post->ID, $comment_author, $comment_author_email));
}


Or you can just replace the whole section if you want. Look carefully but, this should start at line 642 and end at line 659

function comments_template( $file = '/comments.php', $order = 'DESC' ) {
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;

if ( ! (is_single() || is_page() || $withcomments) )
return;

$req = get_option('require_name_email');
$commenter = wp_get_current_commenter();
extract($commenter, EXTR_SKIP);

/** @todo Use API instead of SELECTs. */
if ( $user_ID) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date $order", $post->ID, $user_ID));
} else if ( empty($comment_author) ) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date $order", $post->ID));
} else {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date $order", $post->ID, $comment_author, $comment_author_email));
}


That’s it! Works for me…

Here is the link to where I found this.

After all that I found THIS. But, I have not tried it.

Webmasters! Check out these money makers!!!!

Banned from Google? Check out this post!

This is so amazing I had to put it here.
Get the kit HERE!
water-for-gas.jpg

12 Responses to “WordPress comment sort order”

  1. Greetings….. | Zentode on August 16th, 2008 8:46 am

    [...] through mine here you may want to check out these money makers!!!! You will also find a handy WordPress comment sort order tweak there too. All at [...]

  2. Gerro on September 22nd, 2008 10:04 pm

    This could work, but if you just want the sort to work for a specific theme, I suggest sticking to the comments.php.

    I’ve found a quick fix that requires only a single line of code to be added on the comments.php to work.

    I posted in my blog a short article on the solution to the worpdress comment sort.

  3. Zentode on September 23rd, 2008 8:08 am

    Excellent solution. Thanks. I will have to try this. Way better than having to refer to notes on what to change with every PHPWS upgrade. Thanks for the post.

  4. Web Your NameĀ® Marketing & Advertising on May 30th, 2009 7:52 am

    YOU ROCK, after using countless stupid mods that didnt work, i coded your text above and it fixed it ………!!

  5. Stephanie on June 6th, 2009 12:37 pm

    Hi there! Nice job You’re doing. If You would like to participate to our pay per click in-text program, please register. Regards

  6. Esther on June 19th, 2009 7:13 am

    There is also a plugin available
    http://wordpress.org/extend/plugins/comment-sorter/

  7. Jaesten on July 5th, 2009 11:05 am

    Thanks dude!

    It worked!

    Tried a bunch of things, but this was the solution!!

    Thanx once more!

  8. angelina jolie on September 10th, 2009 12:19 pm

    I love your site. :) Love design!!! I just came across your blog and wanted to say that I

  9. Mr.Carrot55 on October 22nd, 2009 4:20 pm

    Nontheless, citizens need to participate in decision-making about important issues and be provided with opportunities to deliberate with those who can inform the discussion. ,

  10. majkl on November 17th, 2009 12:19 pm

    works great !

  11. celebrity fuck you on August 24th, 2010 2:34 pm

    Sign: zdbrw Hello!!! atwzv and 1233pmhmudwzku and 4409 : I love your site. :) Love design!!! I just came across your blog and wanted to say that Ive really enjoyed browsing your blog posts.

  12. LEE on September 2nd, 2010 3:52 am

    Thank you for review a valuble article. This useful for me and my friend, I will follow your blog for continue reading your news.

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!





  • HOT STUFF

  • Works GREAT!

  • $25 Sign up BONUS! LIMITED TIME!

    Earn $$ with WidgetBucks!
  • The way to go

  • Random Sites

  • I love this!

  • SECRET DEAL!

    US - PC-cillin 2008
    I was just approved to promote this! Enter coupon code: TrendAVS08 and get 20% off! You're welcome!
  • SK8ERS!

    Top Skate & Surf Brands at Pacsun.com
  • Seriously – I listen all day!

    Sirius Satellite Radio Inc.
  • I use this frequently

  • Guestbook





Hosted by the creator. Want one? $100 a year! Contact Me   Activism Blogs - BlogCatalog Blog Directory