Add tertiary links to your Drupal template
By default, Drupal gives you two menu variables to use in your templates. $primary_links contains the first level of navigation and $secondary_links contains the child pages of the active primary link.
But what if you need to display the children of the secondary links? Fortunately, Drupal user rapidsynergy has done the hard work for us in this comment he posted on the Drupal website. I'll reproduce his code here (with slight modifications) for future reference.
Copy and paste this function into template.php, which resides in your themes folder:
<?php
/**
* Returns an array containing the tertiary links based on the primary menu.
* Tertiary links can be either a third level of the Primary links
* menu or generated from a second level of the explicitly defined secondary_menu
*/
function menu_tertiary_links() {
$primary = variable_get('menu_primary_menu', 0);
$secondary = variable_get('menu_secondary_menu', 0);
if (!$primary || !$secondary) {
//primary and/or secondary links disabled - ergo no tertiary links should be available
return NULL;
}
if ($secondary != $primary) {
//secondary menu is different from primary - return children of explicitly defined secondary
return menu_primary_links(2, $secondary);
} else {
//all based on primary - return the third level accordingly
return menu_primary_links(3, $primary);
}
}
?>Next, make your tertiary menu available as a variable to your theme template by adding this function to template.php:
<?php
function _phptemplate_variables($hook, $vars = array()) {
$vars['tertiary_links'] = menu_tertiary_links();
return $vars;
}
?>Finally, you can add the following snippet to output the tertiary links in your theme:
<?php if ($tertiary_links): ?>
<div id="tertiary-links">
<?php print theme('links', $tertiary_links, array('class' => 'links tertiary-links')) ?>
</div>
<?php endif; ?>Comments
i am trying the Drupal
i am trying the Drupal template, your posts help me a lot! thanks!
Delicious
Digg
StumbleUpon
Reddit
Facebook
Technorati




