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

		
Advertisements

One thought on “Tertiary links / 2: tree workaround

  1. keven

    Great stuff, thanks for this! Small amendment:

    Template.php ->

    Function name is mytheme_menu_tree_secondary

    page.tpl.php, call:

    print theme(‘menu_tree_secondary’, variable_get(‘menu_primary_menu’, 0));

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s