While converting my Netoteric site to Drupal, there was a small problem with the portfolio page. The items in it alternate between left and right. Views Theme Wizard didn’t work. It was time for more desperate measures.

I added a function in my custom template file, which created an index number and assigned it to a node member.

/**
 * Display the nodes of a view as plain nodes.
 */
function theme_views_view_nodes_portfolio($view, $nodes, $type, $teasers = false, $links = true) {
	$i=0;
  foreach ($nodes as $n) {
    $node = node_load($n->nid);
		$node->__views_index_number = $i++;
    $output .= node_view($node, $teasers, false, $links);
  }
  return $output;
}

theme_views_view_nodes_portfolio overrides the Views default theme function, but only for the portfolio view.

Then inside the contemplate body template I just added a modulo function to alternate between left and right:

<div 
class="thumbnail <?=($node->__views_index_number % 2 ? ‘right’:‘left’)?>">

And voila! Now the images alternate between left and right…