Drupal: How to Theme Menu

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


Snippet on this page works for Drupal 5. Please refer to the link: for complete Drupal 6 menu theming tutorial.

Continue with the snippet below for Drupal 5.

Following theme function needs to be put in your drupal theme's template.php: 

<?php
function phptemplate_menu_tree($pid 1) {
 if (
$tree menu_tree($pid)) {
  
$output .= "<ul id=\"foo\" class=\"bar\">";
    
$output .= $tree;
    
$output .= "</ul>\n";
    return 
$output;
  }
}

function 
phptemplate_menu_item($mid$children ''$leaf TRUE) {
  return 
'<li id="menu-item-'.$mid.'" class="bt_1">'menu_item_link($mid) . $children ."</li>\n";
}

function 
phptemplate_menu_item_link($item$link_item) {
  if (
$item['title'] == 'Login') {
    
$attributes['title'] = $link['description'];

global 
$user;

if (
$user->uid 0){
    return 
l('Logout'"logout", !empty($item['description']) ? 
array(
'title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}
}
    return 
l($item['title'], $link_item['path'], !empty($item['description']) ? 
array(
'title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}
?>

Now you can call the menu in your page.tpl.php as:

<?php
 $menuhtml 
theme_menu_tree(67);
 print 
$menuhtml;
?>

                                     
-1 points

Great article . Will definitely copy it to my site.Thanks.

Anonymous's picture
Created by Anonymous

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 <% ... %>.