How to: reverse WordPress comments order

Most blogs displays comments from the older to the younger. I have seen many bloggers who asked how to reverse the comment list order, so here’s a recipe.
That’s super easy: We only need the array_reverse() php function.

For those who knows at least a bit of the php programming language, you probably already heard about the array_reverse() function. This function takes an array as argument, and return it reversed.

Just open the comments.php file from your theme. Find the following line:

<?php foreach ($comments as $comment) : ?>

Now, add this line below:

<?php $comments = array_reverse($comments, true); ?>

The code should look like this:

<?php $comments = array_reverse($comments, true); ?>
<?php foreach ($comments as $comment) : ?>
   	// comments loop
<?php endforeach; ?>

That's all. Comments are now displayed in reverse order.

11 Responses

Oct 28 2008 17:06

I did it! Thanks!

Jan 03 2009 23:56

Very nice little trick!

Aug 24 2009 16:27

Brilliant. So simple but it does the job. Thanks.

Aug 24 2009 22:14

Thanks for this quick solution :)

Aug 28 2009 19:00

Definitively it works
all the software shoud be like this, easy and simple…
thx

Oct 23 2009 08:28

Million thanks! Very helpfull!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required