I want to display the sub menus of the currently accessing primary link as a block. Drupal provides Primary links, Secondary links blocks but does not display sub menus of currently accessing primary link.
When I search, I got following code snippet which lists the sub menus of currently accessing primary link. I directly created block using Add block by adding this php code snippet. It works a charm.
$tree = menu_tree_page_data('primary-links'); //substitute your menu name for primary-links
foreach($tree as $key => $mi) {
if ($mi['link']['in_active_trail'] && $tree[$key]['below']) {
$menu = menu_tree_output($tree[$key]['below']);
}
}
print $menu;
I hope this will help others to find easily.
Awesome! Worked like charm
Was searching exactly for this code.
Thanks a bunch!
this is great help and very much easy thanks
Thanks alot !!
iv’e been searching for this command for a while, thanks again =]
Cool! I have am using secondary links with the theme “giordani”. Is there a way to do this with secondary links? Thank you.
Yes you can display sub menus of secondary links by changing the above code. In place of primary-links use seconday-links. That means code will be
$tree = menu_tree_page_data('secondary-links'); //substitute your menu name for primary-linksforeach($tree as $key => $mi) {
if ($mi['link']['in_active_trail'] && $tree[$key]['below']) {
$menu = menu_tree_output($tree[$key]['below']);
}
}
print $menu;
is it can show like drop down menu sir?
If you want to show drop down of menu items, use nice_menus module
Thanks for sharing!!!
Just what I needed.
Hi, guys.
That trick was really helpful. I was wondering though:
Is there any trick for keeping the primary link in focus when any child menu item is pressed?
Thank you in advance.
Drupal by default add the class “active-trail” to the parent item. You just need to add css for that element.
good day, i’m new to drupal..where do i put the code snippet on the block? i’m using drupal 6 and the wabi theme…thnx in advance
Yes, you have to keep the code in block. From drupal admin interface go to add block page and past the code and choose the input format as php-mode.
Could you please tell me for which theme this code works.
Thanks
Yes, it will work for any theme
How it is with 2 Submenu’s from primary links.
For sub menus the best option is menu block module.