My site nav is all in a single menu: main-menu, eg:
- Home
- About
- Director Name 1
- Director Name 2
- Contact
My site navigation bar comprises two horizontal strips: the upper one lists all top-level pages (ie: Home, About, Contact, Services). The lower one should be populated with the revelant sub-menu items for the current page. So if you're on the Home page, the bar will be empty. If you're on the About page, the bar will contain links to each of the Directors pages.
My top menu is populated by the following, unchanged from the code in the default page.tpl.php:
<?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix')))); ?>
To get the sub-menu items, however, I've had to add the following to my theme's template.php:
function mytheme_preprocess_page(&$vars){
$vars['page_submenu'] = NULL;
$main_menu_tree = menu_tree_page_data('main-menu', NULL, TRUE);
foreach ($main_menu_tree as $menu_item) {
if (count($menu_item['below']) > 0) {
$submenu = $menu_item['below'];
}
}
if ( !empty($submenu)){
$vars['page_submenu'] = menu_tree_output($submenu);
}
}
... basically, "get the main menu, find the menu item in it that has some "below" items, and return that "below" bit as a menu tree".
I can then just render that in the template:
print drupal_render($page_submenu);
This seems a bit kludgy. Returning only the submenu items for the current page would seem like a fairly common requirement - is there a better way to do it?