Zebra stripes on taxonomy list

Note from the handbook maintainers: This snippet hacks a core file. This is always a bad idea and the theme should be overridden with template.php instead of hacked. Use this snippet at your own risk.

Would you like theme your taxonomy list with zebra stripes (alternating lines of color)?

You need change theme.inc

function theme_links($links, $attributes = array('class' => 'links')) {
  $count = 1;
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = '';

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
        $class = $key;
      }
      else {
        $link['attributes']['class'] = $key;
        $class = $key;
      }

  if ($count++ % 2) {
        $output .= '<li class="'. 'odd">';
        } else {
        $output .= '<li class="'. 'even">';}

      // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

      if (isset($link['href'])) {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}

Original Code have extra_class to Add first and last classes. I think it is not very useful so just remove it or comment with // (but it is educational and should be there)

Hope be Useful.

 
 

Drupal is a registered trademark of Dries Buytaert.