How to create a Sub-Menu?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
hajer's picture

i want to create a sub-menu for the" primary link" menu . how can i do that?

Comments

I'm plagiarizing from

Adam S's picture

I'm plagiarizing from Lullabot's "Using Drupal" published by O'Reilly press (buy a copy so they don't get mad at me) page 26. It covers the basics. http://www.amazon.com/Using-Drupal-Angela-Byron/dp/product-description/0...

Although under normal conditions, primary and secondary links are two different menus, there's also a setting under Adminitster->Site building ->Menus->Settings tab(admin/build/menu/settings) to make the same menu contain both the primary and secondary links. This creates a sort of "drill-down" effect in which the top-level items are displayed as the primary links, and any subitems are displayed as secondary once the main section is clicked on.

Marine job board with Drupal 7 at http://windwardjobs.com

Can someone flesh-out that

ithacaindy's picture

Can someone flesh-out that suggestion? For instance, I have a "Local" menu item in the primary links menu. I have a "Politics" item in secondary links that is attached to the "Local" menu item. However, when I hover over the "Local" menu item, the "Politics" sub-menu doesn't appear. (There are articles in the "Politics" category.) What am I missing?

Ok, the hovering stuff

Adam S's picture

Ok, the hovering stuff requires some JavaScript. If you want a two tiered static menu then you will have to first follow the instructions above. Then under primary menus at yoursiteurl.com/admin/build/menu-customize/primary-links you will have to move the cross hairs by indenting them one and click save.

x Politics (primary)
  x Glenn Beck is a wack job (secondary although following rules above it corresponds to primary)
  x FoxNews political views will eventually lead to the failure of the US (secondary)
x Food (primary)
  x Kit Kat bars rule (secondary)
  x Nigela Lawson and Rachel Ray inspire me to cook (secondary)

Politics | Food
Glenn beck | FoxNews

Politics | Food
Kit Kat | Nigela Lawson

Marine job board with Drupal 7 at http://windwardjobs.com

Ok, the hovering stuff

Adam S's picture

Ok, the hovering stuff requires some JavaScript. If you want a two tiered static menu then you will have to first follow the instructions above. Then under primary menus at yoursiteurl.com/admin/build/menu-customize/primary-links you will have to move the cross hairs by indenting them one and click save.

x Politics (primary)
  x Glenn Beck is a wack job (secondary although following rules above it corresponds to primary)
  x FoxNews political views will eventually lead to the failure of the US (secondary)
x Food (primary)
  x Kit Kat bars rule (secondary)
  x Nigela Lawson and Rachel Ray inspire me to cook (secondary)

Politics | Food
Glenn beck | FoxNews

Politics | Food
Kit Kat | Nigela Lawson

Marine job board with Drupal 7 at http://windwardjobs.com

Once more for those slow

ithacaindy's picture

Once more for those slow among us (myself included.)

  1. Go to admin/build/menu/settings
  2. Set "Source for Secondary Links" to Primary.
  3. Go to admin/build/menu-customize/primary-links
  4. Create "Glenn Beck" menu item.
  5. Move "Glenn Beck" under "Politics".

This is where I get lost. Do I create "Glenn Beck" as a sub-menu of "Politics" in the Primary menu, Secondary menu, or both?

Once you set "Source for

Adam S's picture

Once you set "Source for Secondary Links" to Primary, all links will be found in your primary menu settings page, or at least that is where they should be. In this case you need to indent the child links under the parent link in the primary menu settings page. Another way to do this is to set the parent of the link in the menu link creation page.

You might want to experiment with this a little. Just try moving the cross hairs around the menu settings page. See what happens.

p.s. When it comes to learning Drupal we are all slow.

Marine job board with Drupal 7 at http://windwardjobs.com

Does it really make a

stattler's picture

Does it really make a drop-down menu with OP? I know this works with many other themes, but its not working with OP, on my site. Do I need any extra module for this?

Yes, for a drop-down menu you

Adam S's picture

Yes, for a drop-down menu you will need to use Nice Menus. For a dynamic two tiered menu you will need Dynamic Persistent Menu or use the Superfish which may or may not work with ie7 and ie8. If you use the Nice Menus or Dynamic Persistent Menu you will have to create a block in the page-header.tpl.php file to hold the block region.

Which do you guys want to use and I will give my best tutorial?

Marine job board with Drupal 7 at http://windwardjobs.com

My choice is for the most

ithacaindy's picture

My choice is for the most bullet-proof plug-and-play method that doesn't require too much crawling around in the innards of OP's theme.

Nice menu or Superfish, any

stattler's picture

Nice menu or Superfish, any one is fine. I guess the procedure would be similar for each modules. I would like to know how to create a container in the theme's tpl file so that the menu can be put into it. Also, in that case, I would like to know how the default menu can be removed/replaced.

Looking forward to you, Adamsohn.

Upload Nice Menus to

Adam S's picture
  1. Upload Nice Menus to sites/all/modules http://drupal.org/project/nice_menus
  2. Replace openpublish_theme.info and page-header.tpl.php (remove the .txt http://groups.drupal.org/files/openpublish_theme.info_.txt | http://groups.drupal.org/files/page-header.tpl_.php_.txt)
    2 1/2. Clear cache.
  3. Configure Nice Menu block at admin/build/blocks
  4. Configure context global (the top one.... a little confusing in the screen cast)

My crappy screencast..... http://fluxgatemedia.com/sites/default/files/nice-menus_demo.swf (use the slider at the bottom and hold down the mouse button. It goes so much faster.)

Marine job board with Drupal 7 at http://windwardjobs.com

Success. I now have a

ithacaindy's picture

Success. I now have a drop-down menu. Not to look a gift-horse in the mouth, but the drop-down came at the price of crummy-looking menus. Any way of retrieving the original styling?

That's funny. Well, we have a

Adam S's picture

That's funny. Well, we have a couple of choices. First, we can decide how the menu should look and write some CSS to make it pretty. Since it's now rendering a block we can now use other menu modules such as Dynamic Persistent Menus http://drupal.org/project/dynamic_persistent_menu or Superfish http://drupal.org/project/superfish.

This is a good time to learn a very important lesson. Backup, backup, backup. http://drupal.org/project/backup_migrate Get this module set up with cron so that it does a back up everyday or in my case four times a day. Everytime you make a big change to the site make a manually backup and keep it on the server for easy access to revert. I've already reverted my devel site at least ten times today. I like to break things. We changed two files so you can either copy over them using the original files from the OP download or we can change the code back to normal.

  1. Go to admin/build/modules and disable the Nice Menus module. I don't remember if it needs to by uninstalled but before you delete the module from the file system click the uninstall tab on the modules page and uninstall it.

  2. delete nice menus from the file system if you're not going to use them.

  3. This is lines 62 - 66 of page-header.tpl.php

      <div id="nav" class="clearfix">
        <?php if ($nav) : ?>
          <?php print $nav; ?>
        <?php endif; ?>
      </div> <!-- /#nav -->

Change it back to this:

<div id="nav" class="clearfix">
    <?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; ?>
  </div> <!-- /#nav -->

Then you need to delete line 34 in openpublish_them.info since it won't do anything anymore:
regions[nav] = Navigation

Last clear cache and things should be back to normal.

Marine job board with Drupal 7 at http://windwardjobs.com

Once bitten, twice shy. I

ithacaindy's picture

Once bitten, twice shy. I backed-up the original files before making any changes. I disabled the nice-menus module, deleted the module, renamed page-header and openpublish_theme.info. I cleared the cache The nice menu is gone, but the original menus hasn't returned. Were any changes made to the menus?

Did this ever work?

shinz83's picture

I'm confused by the chain here. Did this method ever really work?

Fixed. Somehow I didn't

ithacaindy's picture

Fixed. Somehow I didn't back-up the files. The menu is back and as soon as I finish this sentence I will be installing the backup module. Thanks for saving my bacon.