How to Theme Drupal Menu Tree

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


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=$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";
}
?>





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.