Drupal Articles » Creating hierarchical menus » Create a menu hierarchy using Primary and Secondary links
Note: Lullabot has also provided an excellent video lesson on this same method of Using Secondary Menus to create a menu hierarchy.
- Ensure that both the Primary links and Secondary links menus are being included within the page.tpl.php file of your theme. The following is the default code for this from the Garland theme:
<?php if (isset($primary_links)) : ?>
<?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>
<?php endif; ?>
<?php if (isset($secondary_links)) : ?>
<?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?>
<?php endif; ?> - Go to Administer > Site building > Menus > Settings (admin/build/menu/settings).
- Drupal 5:
Set the Menu containing secondary links option toPrimary links, and set the Restrict parent items to option toPrimary links. Press the "Save configuration" button. - Drupal 6:
Set every option on the page toPrimary links, and press the "Save configuration" button.
The Restrict parent items to (Drupal 5) and Default menu for content (Drupal 6) are the same option. What it does is makes the "Primary links" menu the default menu to add to when creating content, instead of showing a huge list of other menus you don't need.
The Menu containing secondary links (Drupal 5) and Source for the secondary links (Drupal 6) are the same option. What it does is cause the source of the Secondary links menu to be the contextual children of the Primary links menu items, instead of being a separate unrelated "secondary menu". By default the Secondary links menu is a not connected to the Primary links menu - it is second separate menu. This ties the two together.
- Drupal 5:
- Go to Create content > Page (node/add/page). Enter
Sectionfor the Title of this page. Click the "Menu settings" fieldset. AddSectionas the Menu link title, and ensure that the menu is set withPrimary Linksas the Parent item. Leave the Weight field at its default at this point, as it's much easier to sort menu items later from the main Menu page. Click the "Save" button to save the page. - Go to Create content > Page (node/add/page). Enter
Subpagefor the Title of this page. Click the "Menu settings" fieldset. AddSubpageas the Menu link title, and under Parent item, chooseSection, making this page a child of Section in the menu. Click the "Save" button to save the page. - Click on "Section" in the Primary Links menu at the top of the page. You should now see the "Subpage" link already showing in a separate location below it, which is where $secondary_links has been defined in the page.tpl.php template file.
- After you've repeated the process to add more Secondary links within the "Section" menu item, go to Administer > Site building > Menus > Primary links. If you're using Drupal 5, adjust the weight settings to sort the menu in the correct order. If you're using Drupal 6, drag and drop the menu items into the correct order. When you're done sorting, press "Save".

HI Dude, This is very good narration of how to nest the menu links.
Thank you very much and wish more such postings.
This was very useful for a newbie like me. Thank you for the article! :) Drupal seems immensely powerful and neat, but it's still funny how it sometimes takes two hours of googling to find out how to do simple things like this.
I notice that this spits out the menu with the only children being the ones of the current page... is there a way to loop through the entire menu tree and cleanly (without all of that class crap Drupal spits out) display the entire menu?