Drupal Tutorial: Create a menu hierarchy using Primary and Secondary links

Use this configuration technique to get Drupal to connect your primary and secondary menus, so that when a top level menu item is selected, its children menu items will be displayed in a separate (secondary) menu, which you can position elsewhere on your page.

Lullabot has also provided an excellent video lesson on this same method of Using Secondary Menus to create a menu hierarchy.
  1. 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: 'links primary-links')) ?> 'links secondary-links')) ?>

  2. Go to Administer > Site building > Menus > Settings (admin/build/menu/settings).

    • Drupal 5: Set the Menu containing secondary links option to Primary links, and set the Restrict parent items to option to Primary links. Press the “Save configuration” button.
    • Drupal 6: Set every option on the page to Primary 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.

  3. Go to Create content > Page (node/add/page). Enter Section for the Title of this page. Click the “Menu settings” fieldset. Add Section as the Menu link title, and ensure that the menu is set with Primary Links as 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.

  4. Go to Create content > Page (node/add/page). Enter Subpage for the Title of this page. Click the “Menu settings” fieldset. Add Subpage as the Menu link title, and under Parent item, choose Section, making this page a child of Section in the menu. Click the “Save” button to save the page.

  5. 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.

  6. 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”.

Back to top