0

I'm able to get second level of the main menu by using below code.

$menu = '';
$menuItems = menu_tree_page_data('main-menu'); 
foreach($menuItems as $key => $m) {
    if ($m['link']['in_active_trail'] && $menuItems[$key]['below']) {
        $menu = render(menu_tree_output($menuItems[$key]['below']));
   }  
}
print $menu;

If I want to get 3rd (like in image below), 4th or 5th level. how this will be done.

enter image description here

1

It is necessary that you want to display this using code?

I have a better solution for you. You can try with this module Menu Block for above achievement

| improve this answer | |
  • ufff! after exhausted and wasted a lot of time and here you come. Thanks block is working as I expected. Thanks again – usmanjutt84 Apr 14 '17 at 6:43
  • Menu Block doesn't load Level 3 if Level 1 is selected. however, I have just found a nice_menu that loads all of child. So I'm gonna add as a answer. – usmanjutt84 Apr 20 '17 at 6:57
  • But nice_menu isn't loads when any active_trail exits. It always load. Its neither fits for my requirement. – usmanjutt84 Apr 20 '17 at 9:31
  • <?php $main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu')); print drupal_render($main_menu_tree); ?> Add this on your header menu. – KrishaWeb Technologies Pvt Ltd Apr 20 '17 at 11:19
  • And disable menu block. This menu_tree help to render all level which you will add in your menu (selected menu) – KrishaWeb Technologies Pvt Ltd Apr 20 '17 at 11:20
0

I have found a module named Nice_Menus that works for me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.