WordPress Alternating Comments Styles

WordPress comments is probably one of the coolest features of WordPress. Our users can interact with our web site, giving us feedback for our articles. More importantly, many times when you go through comments, you can see some interesting conversations going on. Here is a cool way to style your comments, with alternative colors. That way, you can make your comments more user-friendly.

Find in your comments.php file<?php if ( $comments ) : ?>

and replace it with
<ul>
<?php $i = 0; ?>
<?php foreach ($comments as $comment) : ?>
<?php $i++; ?>
<li id="comment-<?php comment_ID() ?>"<?php if($i&1) { echo 'class="odd"';}
else {echo 'class="even"';} ?>

Of course you need to add the css classes to your style.css file. It's nothing hard, you can do it using WordPress code editor...

.odd { background-color: #fcf9fc; }
.even { background-color: #616161; }

Tags: ,

Author:

One Response to “WordPress Alternating Comments Styles”

  1. Darren McCready says:

    Thanks for the short tut Legolas, this is a very straight forward and easy way to implement a alt style for your comments.

Leave a Comment