Support » Fixing WordPress » Inverse comments order in 2.0

  • Did a search and tried one of the ways to do that but doesn’t work in 2.0 though. I want the comments to show the latest at the top instead of at the bottom. Any idea how to go about doing that? Thanks 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • Download the file /wp-includes/comment-functions.php
    Open it in Notepad or another plaintext editor.

    At the top, around line 14 is this:
    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");

    You need to put a DESC in there at the end, like so:
    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");

    next, look down another couple of lines, and you’ll see another similar statement, the last bit of which is:
    comment_approved = '0' ) ) ORDER BY comment_date");

    Again, stick a DESC in there
    comment_approved = '0' ) ) ORDER BY comment_date DESC");

    Save, upload – and keep a note of what you’ve done for when you upgrade 🙂

    Thanks Podz 🙂

    It’s working.. Just a question.. I’ve got a comment number generated by the following code

    I’ve this at the top of the comments template

    $commentcount=1;

    And this where I want the comment number to show up

    <div class=”commentnumber”><?php echo $commentcount++;?></div>

    When I inverse the comments, the comment number shd be 5, 4, 3, 2, 1 instead of 1, 2, 3, 4, 5..

    Any idea how to change that as well?

    thanks =D

    Errr……..hmm… no ?

    It would need the comment loop to count the comments, set the number then reduce. The last bit is eaasy but I don’t know how to do the first part. Hopefully someone will pass by and drop some code here though!

    Right, thanks Podz..

    Help anyone? Calling for help?

    Any idea how to fix the above?

    🙂

    Errr… I tried doing the DESC thing, and it still doesn’t work. Any idea what could be wrong?

    Did you replaced all the

    comment_approved = ‘0’ ) ) ORDER BY comment_date”);

    with

    comment_approved = ‘0’ ) ) ORDER BY comment_date DESC”);

    Because if you don’t, it wouldn’t work too

    Ahhh, I didn’t realize that I needed to replace the one that’s all the way at the bottom too. Thanks!

    senocular

    (@senocular)

    A (preferred) alternative would be to place this line at the top of your comments.php page in your theme:
    <?php $comments = array_reverse($comments); ?>
    This requires one edit, keeps the order theme specific, and prevents you from mucking around in the WP internals. 🙂

    senocular: thank you for the clean and very easy fix.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Inverse comments order in 2.0’ is closed to new replies.