Community Documentation

Tiered Secondary Links

Last updated July 6, 2007. Created by kingandy on July 6, 2007.
Log in to edit this page.

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.

About this page

Drupal version
Drupal 5.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.