WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Newest comments on top. Possible? (9 posts)

  1. TH
    Member
    Posted 8 years ago #

    Hi. I have set up a weblog for a friend/client and everything is good. But he is very eager to have the most recent comments appear on top rather than on the bottom. Personally I think that it's just annoying to have something that isn't norm. But that is what he wants, bless him.

    Same exact comment features, just flip the list order around. Is this possible at all?

  2. Open up his comments.php and look for this:

    if ($comments) : ?>

    Before it, adding this should do it I'd think:

    $comments = $wpdb->query("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID ORDER BY comment_date DESC");

  3. TH
    Member
    Posted 8 years ago #

    No... unfortunately that didn't do anything. It just shows up as plain text on the page. I just pasted it in exactly like it's here where you said.

    I should mention that I'm running WP 1.5.2

    Thank you for trying to help!

  4. skippy
    Member
    Posted 8 years ago #

    What Viper007Bond pasted was PHP, not HTML, so you need to tell the PHP engine to execute the code. Place <?php before, and ?> after what you pasted, and everything should work:

    <?php $comments = $wpdb->query("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID ORDER BY comment_date DESC"); ?>

  5. TH
    Member
    Posted 8 years ago #

    I knew that code looked funny somehow. :) Still... didn't work this time either.

    This time I got an error message and no visible comments at all;

    Warning: Invalid argument supplied for foreach() in /domain/path/comments.php on line 15

    Line 15 by the way reads
    <?php foreach ($comments as $comment) : ?>

  6. Er, sorry. Replace query with get_results. :)

    <?php $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID ORDER BY comment_date DESC"); ?>

  7. TH
    Member
    Posted 8 years ago #

    Success! It works! Everything looks good and functional.

    Thank you both so much for helping out! This is the first thing that has gone right for me in several days. I shall celebrate this event by going a little wild and having a Caffe Latte and a crosword puzzle!

    Thank you again!

  8. Heh, glad to help. :)

  9. Karel
    Member
    Posted 8 years ago #

    Great! I solved this with a comment-functions.php hack, but this is a lot easier!

    Regards,

    Karel

Topic Closed

This topic has been closed to new replies.

About this Topic