Support » Plugins » Newest comments on top. Possible?

  • Resolved TH

    (@th)


    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?

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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");

    Thread Starter TH

    (@th)

    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!

    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"); ?>

    Thread Starter TH

    (@th)

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

    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"); ?>

    Thread Starter TH

    (@th)

    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!

    Heh, glad to help. 🙂

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

    Regards,

    Karel

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Newest comments on top. Possible?’ is closed to new replies.