WordPress.org

Ready to get started?Download WordPress

Forums

Inverse comments order in 2.0 (10 posts)

  1. Truth
    Member
    Posted 8 years ago #

    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 :)

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

    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 :)

  3. Truth
    Member
    Posted 8 years ago #

    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

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

    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!

  5. Truth
    Member
    Posted 8 years ago #

    Right, thanks Podz..

    Help anyone? Calling for help?

    Any idea how to fix the above?

    :)

  6. raytehdorkus
    Member
    Posted 8 years ago #

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

  7. Truth
    Member
    Posted 8 years ago #

    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

  8. raytehdorkus
    Member
    Posted 8 years ago #

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

  9. senocular
    Member
    Posted 8 years ago #

    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. :)

  10. www.onlinecasinoselite.com
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.