Add $zebra class to li tags for ul.menu.

andregriffin - April 22, 2008 - 04:49
Project:Drupal
Version:6.2
Component:menu system
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I am porting a new version of my theme, Framework, to Drupal 6, and in my Drupal 5 version, I used the following override to add $zebra classes to li tags for ul.menu.

<?php
function phptemplate_menu_item($mid, $children = '', $leaf = true) {
static
$count = 0;
$zebra = ($count % 2) ? 'odd' : 'even';
$count++;
return
'<li class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .' ' . $zebra . '">'. menu_item_link($mid) . $children ."</li>\n";
?>

However, I can't figure out how to get this working under Drupal 6. Here is the standard function for Drupal 6.

<?php
function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
 
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty(
$extra_class)) {
   
$class .= ' '. $extra_class;
  }
  if (
$in_active_trail) {
   
$class .= ' active-trail';
  }
  return
'<li class="'. $class .'">'. $link . $menu ."</li>\n";
}
?>

Any help would be much appreciated.

#1

andregriffin - April 28, 2008 - 20:08

Anyone care to take a stab at it?

#2

pegleglax - May 8, 2008 - 04:44

I'm looking for the SAME answer.... anyone out there have a 'quick n dirty'?

#3

dmitrig01 - May 8, 2008 - 04:47
Status:active» fixed

You can do the same thing.

<?php
function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  static
$zebra = FALSE;
 
$zebra = !$zebra;
 
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty(
$extra_class)) {
   
$class .= ' '. $extra_class;
  }
  if (
$in_active_trail) {
   
$class .= ' active-trail';
  }
  if (
$zebra) {
   
$class .= ' even';
  }
  else {
   
$class .= ' odd';
  }
  return
'<li class="'. $class .'">'. $link . $menu ."</li>\n";
}
?>

#4

pegleglax - May 8, 2008 - 05:34

i. frikin. love. you.

dmitrig01 is god.

#5

Anonymous (not verified) - May 22, 2008 - 05:41
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.