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 the Founder of Voosh Themes. I've been designing & developing websites for over 10 years and am interested in just about anything related to design. I also have a PhD in Computer Science (with a particular focus on Interaction Design) - you can follow me on Twitter at @cpcreed.

1 Comment

  1. bryan

    June 9th, 2010 at 10:38 am

    thankss you save my day i was dying for this :)

Leave a Reply