WordPress.org

Ready to get started?Download WordPress

Forums

Descending comments? (13 posts)

  1. Daisyhead
    Member
    Posted 10 years ago #

    I would like my comments to be in descending order instead of ascending. With the newest comments at the top. I believe I checked in my templates-functions.php and could not find where to do this and I went into my edit-comments.php page and changed ever "ASC" that I found there to "DESC" and they are still in ascending order. Can anyone help me out with this?
    Thanks,
    Daisyhead

  2. Lester Chan
    Member
    Posted 10 years ago #

    Open wp-comments.php,
    find

    $comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = '$id' AND comment_approved = '1' ORDER BY comment_date");

    Replace

    $comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = '$id' AND comment_approved = '1' ORDER BY comment_date DESC" );

    Hope that helps.

  3. Daisyhead
    Member
    Posted 10 years ago #

    It sure did work. Thanks GamerZ! =)
    -Daisyhead

  4. Lester Chan
    Member
    Posted 10 years ago #

    No Problem Daisy =)

  5. Tim Griffin
    Member
    Posted 9 years ago #

    And where is wp-comments in 1.5?

  6. Root
    Member
    Posted 9 years ago #

    Its er deprecated in the default anyway.

  7. Kafkaesqui

    Posted 9 years ago #

    "And where is wp-comments in 1.5?"

    Check the comments_template function in wp-includes/comment-functions.php. You'll find two $comments lines where you'll need to add DESC to the SELECT.

  8. Tim Griffin
    Member
    Posted 9 years ago #

    Cool - thanks for Coffee2code.com for e-mailing the instructions for this.
    1. Open wp-includes/comment-functions.php
    2. locate the comments_template section near the top
    3. indentify both strings containing the following:

    $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date"

    4.Change the last part of both lines to: comment_date DESC"

    Thanks Kafkaesqui and Scott Reilly!

  9. yearginsm
    Member
    Posted 8 years ago #

    Anybody know where the hook would be to redefine those variables rather than hacking the core? I'm sure this works, but I like my one-click updates too.

  10. Mark (podz)
    Support Maven
    Posted 8 years ago #

    Descending comments was discussed last week I think ...

  11. yearginsm
    Member
    Posted 8 years ago #

    I've tried about three or four different queries for it, but nothing but this topic comes up in the search results. As an aside, I'm not a huge fan of the new search engine. :-P If you happen to come accross the link to it, mind dropping it in here?

  12. elvix
    Member
    Posted 8 years ago #

    Instead of mucking with program code, which makes upgrading a pain, just edit your comments.php script.

    Under: <?php if ($comments) : ?>

    Add this:
    <?php $comments = array_reverse($comments,true); ?>

    This reverses the order of the comments array, achieving the descending order without changing the db call.

    You could have different comments.php templates (one ASC and on DSC, for example) and just call the one you want into your single templates as you like.

  13. Mysmasken
    Member
    Posted 7 years ago #

    Thanks, this last post was very helpful.

Topic Closed

This topic has been closed to new replies.

About this Topic