Inspiration For Creative Minds
Home » Labs » How to show alternate comment colors in WordPress  

Filed under Labs

By adding below PHP code to your template you can display comments in alternate colors. It uses a counter with an increment and a two CSS classes.

PHP

 
<?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"';} ?>>

CSS Class

 
.odd  { background:#f8f6e4; }
.even { background:#f9f8f0; }
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook
Labs

Posts you may like: