1

I'm using the code below to print my main menu in page.tpl.php:

<?php
$main_menu = menu_navigation_links('main-menu');
print theme('links', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'clearfix'),
),

'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
?>

However, it is only outputting the top-level menus of my navigation. Is there a piece of code I can add that will output submenus too?

  • 1
    Have you tried changing/using/including the $level argument to api.drupal.org/api/drupal/includes%21menu.inc/function/… ? – Jimajamma Feb 16 '14 at 23:03
  • OK thanks - could you please tell me where I could add the argument to my code? – Jane Feb 16 '14 at 23:05
  • 2
    umm, $main_menu = menu_navigation_links('main-menu', RIGHT_HERE);, eg, $main_menu =menu_navigation_links('main-menu', 1); would go down one level, $main_menu = menu_navigation_links('main-menu', 2); would go down two, etc. – Jimajamma Feb 16 '14 at 23:06
  • Wow totally worked! :-) thanks, @Jimajamma - could you please post this as an answer below, so I can select as the correct answer? Thanks so much! – Jane Feb 16 '14 at 23:40
5

Calling menu_navigation_links() with only the menu name by default provides only the top level links. To delve deeper you need to provide the second $level argument, eg:

$main_menu =menu_navigation_links('main-menu', 1);

will provide the top and next level links, and:

$main_menu =menu_navigation_links('main-menu', 2);

will provide one level deeper.

  • I tried to use <?php $main_menu =menu_navigation_links('main-menu', 1); ?> on page.tpl.php and nothing print out. Am I missing something? – CocoSkin Aug 5 '14 at 19:34
  • 1
    Did you actually print it after setting it above? – Jimajamma Aug 9 '14 at 20:45
  • :P forgot to print $main_menu – CocoSkin Aug 11 '14 at 18:09

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.