Override the theme list item function to add odd/even zebra striping

Versions used: 

I think list items should, or have the option to, include zebra striping. For now, it easy enough to just override theme_item_list() and add that ourselves. Place the following code in your themes template.php file, remembering to change the hook to the name of your theme.

<?php
function HOOK_item_list($variables) {
  static
$count = 0; // added

 
$items = $variables['items'];
 
$title = $variables['title'];
 
$type = $variables['type'];
 
$attributes = $variables['attributes'];

 
// Only output the list container and title, if there are any list items.
  // Check to see whether the block title exists before adding a header.
  // Empty headers are not semantic and present accessibility challenges.
 
$output = '<div class="item-list">';
  if (isset(
$title) && $title !== '') {
   
$output .= '<h3>' . $title . '</h3>';
  }

  if (!empty(
$items)) {
   
$output .= "<$type" . drupal_attributes($attributes) . '>';
   
$num_items = count($items);
    foreach (
$items as $i => $item) {
     
$zebra = ($count % 2) ? 'odd' : 'even'; // added
     
$count++; // added
     
$attributes = array();
     
$children = array();
     
$data = '';
      if (
is_array($item)) {
        foreach (
$item as $key => $value) {
          if (
$key == 'data') {
           
$data = $value;
          }
          elseif (
$key == 'children') {
           
$children = $value;
          }
          else {
           
$attributes[$key] = $value;
          }
        }
      }
      else {
       
$data = $item;
      }
      if (
count($children) > 0) {
       
// Render nested list.
       
$data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes));
      }
      if (
$i == 0) {
       
$attributes['class'][] = 'first';
      }
      if (
$i == $num_items - 1) {
       
$attributes['class'][] = 'last';
      }
     
$attributes['class'][] = $zebra; // added
     
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
    }
   
$output .= "</$type>";
  }
 
$output .= '</div>';
  return
$output;
}
?>