WordPress.org

Support

Support » How-To and Troubleshooting » Descending comments?

Descending comments?

  • 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

Viewing 12 replies - 1 through 12 (of 12 total)
  • Lester Chan
    Participant

    @gamerz

    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.

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

    Lester Chan
    Participant

    @gamerz

    No Problem Daisy =)

    And where is wp-comments in 1.5?

    Its er deprecated in the default anyway.

    “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.

    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!

    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.

    Mark (podz)
    Support Maven

    @podz

    Descending comments was discussed last week I think …

    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. 😛 If you happen to come accross the link to it, mind dropping it in here?

    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.

    Mysmasken
    Member

    @mysmasken

    Thanks, this last post was very helpful.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Descending comments?’ is closed to new replies.