How to Theme Drupal Menu Tree
Following is the code that is being used to theme Drupal 6 menu tree where "clean" is the theme being used:
<?php
function getMenuItemCounter($case=null){
static $counter = 1;
return ($case == 'reset') ? $counter=1 : $counter++ ;
}
// theme_menu_tree()
function clean_menu_tree($tree) {
getMenuItemCounter("reset");
return '<ul class="menu">'. $tree .'</ul>';
}
// theme_menu_item()
function clean_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';
}
$counter = getMenuItemCounter();
$class .= " item_".$counter;
return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
}
?>