My event list on one of my drupal sites is long, so I wanted to stripe alternating events in the list by changing their color. I created a new function in event.theme right after theme_event_upcoming_block using a copy of the theme item_list code:

<?php
function theme_event_upcoming_block_stripe($items) {
  $output = '<div class="item-list">';
  if (isset($title)) { $output .= '<h3>'. $title .'</h3>'; }

  $output .= '<ul>';
  $x = 0;
  while (isset($items[$x])) { 
	$output .= '<li class="odd">'. $items[$x] .'</li>';

  	if (isset($items[$x+1])) {
  		$output .= '<li class="even">'. $items[$x+1] .'</li>';
  	}
  	$x = $x+2;
  }
  $output .= '</ul>';
  $output .= '</div>';
  return $output;
}
?>

then in event.module, I simply modified:

  $output = theme("event_upcoming_block", $items);

to be:

  $output = theme("event_upcoming_block_stripe", $items);

finally, to event.css I added:

li.even {
	background: #cccccc;
}

You could customize the even or odd css to your taste.

Works well for me, and looks nice.

Comments

scroogie’s picture

If you use

$cycle = array('odd', 'even');
$count = count($items);
for ($i = 0; $i < $count; $i++) {
   $output .= '<li class="'.$cycle[$i % 2].'">'.$items[$i].'</li>';
}

This saves the isset and if on every iteration.

tdailey’s picture

definitely more efficient. For those playing along at home, the whole function is now:

<?php
function theme_event_upcoming_block_stripe($items) {
  $output = '<div class="item-list">';
  if (isset($title)) { $output .= '<h3>'. $title .'</h3>'; }

  $output .= '<ul>';
  $cycle = array('odd', 'even');
  $count = count($items);
  for ($i = 0; $i < $count; $i++) {
    $output .= '<li class="'.$cycle[$i % 2].'">'.$items[$i].'</li>';
  }
  $output .= '</ul>';
  $output .= '</div>';
  return $output;
}
?>