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.
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.
15 Responses
I did it! Thanks!
Very nice little trick!
Brilliant. So simple but it does the job. Thanks.
Thanks for this quick solution
Definitively it works
all the software shoud be like this, easy and simple…
thx
Million thanks! Very helpfull!
Cool! Thanks a lot
Very strange. I have put your code in the template but it creates an infinite loop so the page keeps on loading and reloading comments.
My bad, i thought it read to add the line below the first part of the code… works well.
very good but when i am logged in as admin the order isn’t changed it is only changed when I am not logged in (which is fine for the public) but it looks a bit odd when people are editing the site
Trackbacks: