Add tertiary links to your Drupal template
Update: For a version of this snippet compatible with Drupal 6, see Add tertiary links to your Drupal 6 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
willy at 14:02 on 04-Aug-2008
i am trying the Drupal template, your posts help me a lot! thanks!
rob at 12:47 on 06-Jan-2011
Two things, Mark: This is for Drupal 5 only (see the link above for a D6 compatible version), and check you've cleared the site cache.
Anonymous at 2:14 on 12-Aug-2011
Moncler Doudoune,une marque de luxe et de mode.
Moncler Doudoune 2011 st célèbre pour son matelassés vestes de ski et de plein air-porter. Fabriqué à partir de canard à la collection est célèbre pour ses pièces, mais légère, chaude qui vous emmènera de vacances d'hiver au plus à la mode des armoires de la ville. Le port de gilets de Moncler Veste ne vous fera pas comparer flottait. Nous sommes une ligne fiable Doudoune Moncler magasin, maintenant, en fournissant divers produits Moncler approprié pour quatre saisons. Par exemple Doudoune Moncler Femme,Doudoune Moncler Homme,et ainsi de suite.
Chaussure Puma est l’une des plus grandes entreprises au monde dans le domaine du sport et du lifestyle. Puma Chaussures débute avec le sport et finit avec la mode.Les domaines Sport Performance et Lifestyle englobent les catégories football, running, sport automobile, golf, voile et PUMA Archive la collection vintage de la marque.Basket Puma a lancé des produits cultes tels que la Puma Speed Cat, Mostro, PUMA Suede, La veste T7 Track ou encore la chaussure King. La plupart de ces produits ainsi que plein d’autres sont disponibles dans la boutique en ligne officielle de PUMA.60% de réduction.100% Satisfaction Dernières Guarantee.Puma Chaussures 2011 pas cher Vente chaude!Puma Pas Cher,Livraison gratuite!
Melbourne Golf Courses at 0:14 on 14-Jan-2012
Great article guys! Anyone know of any good golf travel websites? Ones similar to this one I found for Melbourne Golf Courses in Victoria.Melbourne Golf Courses






