Drupal: How to Theme Menu



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;
?>



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