Home > Web > Two Useful WordPress Tips With Comments

Two Useful WordPress Tips With Comments

December 11th, 2006

If you like to use WordPress, here are three tips for handling your comments in a more effective manner. I strongly recommend you use the tips in conjunction with SpamKarma2, a very effective WordPress plugin for stopping 99% of spam posts.

Tip 1: Control The Order Of Your Comments

By default, WordPress will display your comments in ascending date order. However, if you would like your comments to appear with the most recent first, you will need to make a small but easy change to your theme’s comments.php file. Here is how to do it:

  1. Connect to your webserver and inside the theme’s folder, search for the file named comments.php and open/edit it
  2. Find this line:
    <?php foreach ($comments as $comment) : ?>
  3. Above that line, add this code:
    <?php $comments = array_reverse($comments, true); ?>

Now your comments will be in descending date order. To revert back to ascending date order, either remove or comment this new line of code.

Tip 2: Prefix Your Comment With A Comment Order Number

Some people like to prefix the comments shown with a comment number. Some themes do this automatically, but if you would like to add this feature to a theme, here are the steps required to do this:

  1. Connect to your webserver and inside the theme’s folder, search for the file named comments.php and open/edit it
  2. Find this line:
    <ol class="commentlist">
  3. Above that line, add this code:
    <?php $count = count($comments); ?>
  4. Now find this line:
    <?php endforeach; /* end for each comment */ ?>
  5. Above that line, add this code:
    <?php $count--; ?>
  6. Finally, find this line:
    <cite><?php comment_author_link() ?></cite> Says:
  7. Above that line, add this code:
    <?php echo $count; ?>)

Now your comments will be prefixed with a number and a bracket eg. 9) — you can change the ) to any character you like or remove it all together, it’s your choice.

Web ,

Comments are closed.