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?
Post new comment