How to add classes to every X number of node in a array
For node listings for which the node.tpl.php (or a different node template) is being used you have variables like $zebra and $id at your disposal that you can use for this kind of tasks. You can see all the available variables with descriptions in the node modules node.tpl.php file or here.

For example if you want to add the necessary class to this line:

&lt;div id="node-&lt;?php print $node-&gt;nid; ?&gt;" class="&lt;?php print $classes; ?&gt; clearfix"&lt;?php print $attributes; ?&gt;&gt;


you could use code snippets like these:


&lt;?php $classes .= ' '.$zebra; ?&gt; - add 'odd' to every first and 'even' to every second node in the list
&lt;?php if (!($id % 2)) $classes .= ' last'; ?&gt; - add 'last' class to every second node.
&lt;?php if (!($id % 3)) $classes .= ' last'; ?&gt; - add 'last' class to every third node.