Tiered Secondary Links

Last modified: July 6, 2007 - 12:28

The standard 'secondary links' functionality - selecting the same multi-tier menu as your primary links - only caters for one submenu layer to be displayed. What if you want a menu that behaves as the navigation block, expanding to submenus when appropriate?

This code snippet can be placed in a block, and will do just that.

<?php
$primary_menu_id
= variable_get('menu_primary_menu', 0);
if (
menu_in_active_trail($primary_menu_id)){
 
// 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[1];
 
$menu_item = menu_get_item($mid);
  print
'<h2>'.$menu_item['title'].':</h2>';
 
$menu_tree = menu_tree($mid);
  print
'<ul class="menu">'.$menu_tree.'</ul>';
}
?>

_menu_get_active_trail() code developed with help from this forum thread.

 
 

Drupal is a registered trademark of Dries Buytaert.