How to show alternate comment colors in WordPress

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; }

Related posts:

HTML5 page structure

HTML5 offers more powerful structure comparing to older versions of Html. There are many new …


Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us