Using the menu.module to maintain you primary and secondary menus

Posted by gordon on Sun, 13/02/2005 - 12:40pm

One of the things that I have been disapointed with drupal is the method of maintaining the primary and secondary links at the top of the times. At this time I think there is the standard method plus one for each theme engine. A lot of different ways to do the same thing. All these methods are pretty useless, and does allow for the ability to take the best advantage of the current web technologoes.

Drupal does however have one method that is extremely flexiable, and will be able to allow theme designers to take the best use of the current technologies. This is the menu module which is used for the navigation menu, and as I will demonstrate can be used for the primary and secondary menus.

The problem is that only theme engines that allow the execution of php code or old style native themes can do this. So the xtemplate theme engine cannot do this without modifing the engine itself.

  1. Using the admin > menu function add 2 new menus. One being the primary and the other being the secondary. Also create any menu items that you want to be displayed on the menu.
  2. Add to your theme in place of the $primary_links and $secondary_links code the following
[?php
$menu = menu_get_menu();
foreach($menu["items"][0]["children"] as $k) {
if ($menu["items"][$k]["title"] == "Primary") {
$mid = $k;
}
}
print theme('menu_tree', $mid); ?]

horizontal menu?

Hi: Thanks for your code. I tried it with PHPTemplate and it worked as described, but I got the menu as it would have been rendered in a block, and I would need it horizontally. I guess that I have to modify som CSS, but I don't know how. I kept the class=secondary-links tag. Thanks in advance!