Output secondary links as a menu tree

21-Nov-2007
Filed under: Drupal, Drupal 5.x

Thanks for this posting goes to rapidsynergy for posting the solution in this comment on the Drupal forum.

Problem: You're using $secondary_links to display the children of the active menu item in $primary_links, but $secondary_links has children too and they aren't displaying when their parent becomes active.

Solution: Add the following snippet to your template.php file:

<?php
/**
* Output $secondary_links as a menu tree.
*/

function secondary_menu_tree() {

 
// get the menu items that lead to the current menu item
 
$active_trail =_menu_get_active_trail();
 
 
// get the menu id of the active top-level link
 
$mid = $active_trail[0];
 
 
// get the primary menus id
 
$pmid = variable_get('menu_primary_menu', 0);
 
 
//do they match?          
 
if ($active_trail[0] == $pmid) {
    return
theme('menu_tree', $active_trail[1]);  //create a tree starting from level 2
 
}

}
?>

Now, add the following line to your theme wherever you want to show the secondary menu items:

<?php print secondary_menu_tree(); ?>