I am using Drupal 7.9. I need to display main menu with sub-menu.

print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => '',
'class' => array('menu'),),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),

That is the code I have used, but it does not show sub-menu items.

Then i have also tried following code :

if ($main_menu){
  $pid = variable_get('menu_main_links_source', 'main-menu');
  $tree = menu_tree($pid);
  $tree = str_replace(' class="menu"', '', $tree);
  $main_menu = drupal_render($tree);
else {
  $main_menu = FALSE;
if ($main_menu): print $main_menu; 

Even it does not display sub-menu.

Does anybody know a solution?


The main menu in Bartik only displays the first level. Since it's hardcoded in page.tpl.php there's nothing you can do about it.

Here's how to get the menu to work properly:

  1. In your theme settings (admin/appearance/settings/barti) disable "Main menu"
  2. Go to admin/structure/block and add the "Main Menu" block to the header region (or wherever you want it)

Alternatively, you can also check out the excellent Menu Block module, which generates extra customizable blocks (1st level, 2nd level, etc) for each menu.

protected by kiamlaluno Aug 22 '15 at 17:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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