Tertiary menus in Drupal

In keeping with the theme of the previous post, here is another fantastic tip for pulling out more levels of your primary links menu.

By default, Drupal gives you primary and secondary links. These can come from the same menu tree; primary links will be the first level, and secondary links will be the second level. But what happens when you want the third level? Drupal does not give you this variable by default.

Tony Mobily from Free Software Magazine shows us the simple way to get at this third menu level.

Basically, he uses Drupal's way to generate secondary links to pull out the tertiary links:

menu_primary_links(2, variable_get('menu_primary_menu', 0) );

By changing the number 2 to 3, we will get the tertiary links. In theory, I think we can probably do more levels i.e. the fourth, fifth, etc. menu levels, too, just by increasing that number. I haven't tried this out, so don't quote me on that.

So to print out your tertiary links (in page.tpl.php for example), use the following code (ideally, I would recommend creating a new variable in the _phptemplate_variables() function):

<?php
$m
= menu_primary_links(3, variable_get('menu_primary_menu', 0) );
print
theme('links', $m, array('class' => 'links tertiary-links'));
?>

Yes, its really that simple! Amazing, eh?

Posted in:

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <b> <i> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <blockquote> <img>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is to block spam bots and check if you're human
A
T
N
A
5
F
Enter the code without spaces and pay attention to upper/lower case.
magnanimous-junior