Alternate styling with PHP
First off, I can’t take any credit for this.
All the credit goes to Paul Denya for the answer, and Elliot Jay Stocks for the question.
EJS asked:
Does anyone know of a way (with PHP) to add an ‘alt’ class to every other <li> in a list? Like how WP does with comments.
(He did this over at http://twitter.com/elliotjaystocks/status/2688884863)
http://twitter.com/elliotjaystocks
![]()
And the answer came back from Paul.
<li class=”<?php foreach((get_the_category()) as $category) { echo $category->category_nicename . ”; } ?>”></li>
Clever yet simple – the hallmark of genius!
You can follow them both at @pdenya and @elliotjaystocks.
Thanks guys!





