Tertiary links / 2: tree workaround
On Tertiary links on Drupal I described a simple approach to display the “tertiary” menu (childrens of secondary menus) on Drupal 5.x. This is an useful but sometimes limiting approach, since the secondary menu disappears when tertiary menu is displayed.
This is an alternative workaround made using a customized menu_tree function:
template.php:
function custom_menu_tree_secondary($pid = 1) {
$menu = menu_get_menu();
$output = '';
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
foreach ($menu['visible'][$pid]['children'] as $mid) {
$type = isset($menu['visible'][$mid]['type'])
? $menu['visible'][$mid]['type'] : NULL;
$children = isset($menu['visible'][$mid]['children'])
? $menu['visible'][$mid]['children'] : NULL;
# display only the children menu of the current menu
if(menu_in_active_trail($mid)) {
$output .= theme('menu_tree', $mid);
}
}
}
return $output;
}
page.tpl.php (in place of standard $secondary block):
<div id="secondary">
<?php if ($secondary_links): ?>
<?php echo tools_menu_tree_secondary(variable_get('menu_primary_menu', 0));?>
<?php endif; ?>
</div>
Tested on:
- Drupal 5.x
- Zen subtheme
Tertiary links on Drupal
Update: check Tertiary links / 2: tree workaround before this. That’s a wiser solution in many cases.
Tested on:
- Drupal 5.x
- Zen subtheme
If you use primary and secondary links in distinct blocks/area of a page, you can add the ability to browse the third navigation level. Just hack your page.tpl.php.
<div id="secondary"> <?php
#display tertiary links menu on 2nd level
$tertiary_links=menu_primary_links(3, variable_get('menu_primary_menu', 0) );
#display secondary links menu on 1st level
if($my_secondary_links):?>
<?php
print theme('links', $my_secondary_links, array('class' => 'links tertiary-links'));
?>
elseif ($secondary_links): ?>
<?php
print theme('links', $secondary_links);
?>
</div> <!-- /#secondary -->
<?php endif; ?>
See also:
- Tertiary menu in Drupal A very useful howto (I saw this trick here)
- Secondary link and third level Topic on drupal.org
Podcast Feed
chirale on twitter
- Alle prossime elezioni regionali fatemi la cortesia di votare qualcuno che abbia a cuore il trasporto pubblico. 5 days ago
Blog Stats
- 242,641 hits
Bring Down IE6
Tags
Blogroll
My Bookshelf
Archives
- March 2012
- June 2011
- May 2011
- January 2011
- October 2010
- July 2010
- April 2010
- December 2009
- August 2009
- July 2009
- May 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- August 2007
Texts double licensed under Creative Commons Attribution - Share Alike license and GNU Free Documentation License. Examples may contain software licensed under GNU General Public License. Images and comments texts aren't necessarily licensed under these terms.



Recent Comments