By tdailey on
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
You can simplify a bit
If you use
This saves the isset and if on every iteration.
thanks
definitely more efficient. For those playing along at home, the whole function is now: