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 |
Jump to:
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
Anyone care to take a stab at it?
#2
I'm looking for the SAME answer.... anyone out there have a 'quick n dirty'?
#3
You can do the same thing.
<?phpfunction 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
i. frikin. love. you.
dmitrig01 is god.
#5
Automatically closed -- issue fixed for two weeks with no activity.