WordPress tutorials: Alternate comment colors

Wpsnipp – If you have a large amount of comments on your blog, it can be very more readable to alternate background colors. In this recipe, I’m going to show you how to do it easily.Adding this code to your comments will allow you to alternate colors in your comments.

 

 

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

You can use this code, for exemple:

.odd  {background: #e5e5e5; }
.even {background: #ccc; }

Leave a comment