A dynamic horizontal tab menu
The most prominent feature here is the horizontal navigation tabs. This has become a popular arrangement recently, very often enhanced with drop-down menus. In our case, there are no drop-down menus. The underlying implementation, however, should be easily extended to host these as well.
Three standard features of Drupal, a PHP theme function and a little CSS magic are used to implement the horizontal tab menu. The features are
- Taxonomies. We use a separate vocabulary "Sections" to organize content.
- The menu is not linked directly to this vocabulary as would the Drupal module taxonomy_menu.module do, but rather is created through a customized menu.
This allow linking menu entries to taxonomy pages, individual nodes, or two column pages generated by the collimator.module. - Finally, links in the menu are cleaned by assigning URL aliases to menu entries.
For example, the entry "partner" links to "partner":/partner which is an alias for "collimator/4":/collimator/4, i.e., the two column listing of teasers for topic 4 ("Lebendiges Netzwerk").
What remains is a function that renders the menu:
<?php
function _contaire_menu($pid = 1) {
$menu = menu_get_menu();
$entries = array();
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children'])
{
foreach ($menu['visible'][$pid]['children'] as $mid) {
$style = (count($menu['visible'][$mid]['children']) ? menu_in_active_trail($mid)
? 'expanded' : 'collapsed')
: 'leaf');
$entry = array('style' => $style, 'link' => theme('menu_item', $mid));
$entry['kids'] = _contaire_menu($mid);
$entries[] = $entry;
}
}
return $entries;
}
function contaire_menu($pid = 1) {
return _phptal_callback('_menu',
array('pid' => $pid, 'entries' => _contaire_menu($pid)));
}
?>In the PHPTAL theme engine we use, this function can be written into the @template.php@ file of our theme and be called from the file @page.tal@ as
<div id="header">
...
<div tal:content="php:contaire_menu(26)" />
</div> Here is the menu entry for our custom menu.
