Displaying WordPress Comments Newest to Oldest

By default, WordPress will display comments in an oldest to newest fashion. This is great for comments that are children or in reply to other comments because you would want to go down the conversation chain in chronological order.

However if you’re running a blog or have a custom testimonials page or something like that and would prefer the comments to go in reverse chronological order, WordPress has you covered.

By now you should be using the wp_list_comments() function to be outputting your comments. It’s been available since WordPress 2.7 and at the time of writing this, we’re currently at 3.6.

Assuming you are using comments the ‘right’ way, look at  your comments.php in your theme folder for the following:

wp_list_comments();

What we need to do is place the $reverse_top_level parameter inside those parentheses, and set it to true. It should look something like this:

wp_list_comments('reverse_top_level=1');

If you’re already using other parameters inside the function, it may look something like this instead:

wp_list_comments('type=comment&callback=updatedComments&reverse_top_level=1');

Voila! You’re finished.

Wait, what’s that? You aren’t using wp_list_comments()? Well get with the program! Nah, don’t worry. There is a solution for you as well. What you’ll be looking for in your comments.php is a line something like this:

foreach ($comments as $comment)

Simply change it to:

foreach (array_reverse($comments) as $comment)

And you’re golden! Admittedly this is the ‘hackier’ way of doing it, so I really would recommend using the proper functions provided by WordPress.

Check out the function reference that I mentioned above for a bunch of other cool things you can do with your comments like setting the avatar size, the amount per page and a crapton more.

Leave a Reply

Your email address will not be published.