By Toe on
I'm making a theme with the PHPTemplates engine. I'd like to be able to alternate between two different classes every time a an item appears on a page. For example, with the teasers that appear on the front page:
<div class="node class1">blah blah blah</div>
<div class="node class2">blah blah blah</div>
<div class="node class1">blah blah blah</div>
Is there an easy way to make the class switch for every instance of an item like that?
Comments
Bumpity. :-/
Bumpity. :-/
Javascript include
Here's an article to make some changes using a simple javascript.
The example basically alternates between two background colors for a table look. I think you could perhaps change this into something that would do the same for you. It involves changing the styles using the DOM.
It's on the great site called A List Apart:
http://www.alistapart.com/articles/zebratables/
I think this would be a lot easier and perhaps applicable to more problems of similar type.
Good luck, and hope it helped.
Dead easy
Just use PHP code like this:
<div class="node node-<?php global $node_count; print ($node_count++ % 2) ? 'odd' : 'even'; ?>">
...
</div>
Thanks! I knew it had to be
Thanks! I knew it had to be possible, but I'm no programmer, so I really didn't know what to do. Had to remove that middle ) tho. :)
eldarin, yours probably woulda worked too, but I try to stay away from JS whenever I can...
could you do this for
could you do this for comments?
trying to get them to be alternating colors