Wordpress Comments – Show Your Most Recent Comments First

Chris Creed / 21st September 2009

Wordpress Comments – Show Your Most Recent Comments First Wordpress Comments – Show Your Most Recent Comments First

By default, when a new comment is added in Wordpress it is added to the end of the list (i.e. older comments are shown first) – however, many Wordpress users like to be able to do the opposite of this (i.e. display new comments at the top of the list).

This is simple to change and can be achieved simply through one line of code. You initially need to access your comments.php file and locate the following block of code:

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

Then, above this section, you need to add the following:

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

All this line does is reverse the comments array that stores details of your comments thus changing the display of your comments from the default oldest to newest, to newest to oldest.

Once you’ve added this line, your code should look something like the following:

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

Save your code and then test – your comments should have now been reversed.

Enjoy This Post? Please Consider Sharing :-)

  • Twitter
  • StumbleUpon
  • Facebook
  • Digg
  • del.icio.us
  • Reddit
  • Technorati

About The Author

Chris Creed

Hi there, I'm Chris and I enjoy writing tutorials and guides on anything web-design related. I also build Premium Web Templates that are available to download on this site. I run things here at Voosh Themes and am currently based in Birmingham (UK) - you can follow me on Twitter at @cpcreed.

Leave a Reply