[consulting] Print Level 3 navigation links

Aaron Winborn winborn at advomatic.com
Thu Dec 3 20:45:13 UTC 2009


I had the same issue at http://drupal.org/node/585950. Here's roughly 
what I did:

// ...
   print theme('links', _tck_menu_navigation_links($menu, $depth), 
array('class' => 'menu', 'id' => 'tck-menu-'. $vars['id']));
// ...

function _tck_menu_navigation_links($menu_name, $level = 0) {
  // Don't even bother querying the menu table if no menu is specified.
  if (empty($menu_name)) {
    return array();
  }

  // Get the menu hierarchy for the current page.
  $tree = menu_tree_page_data($menu_name);

  // Go down the active trail until the right level is reached.
  while ($level-- > 0 && $tree) {
    // Loop through the current level's items until we find one that is 
in trail.
    while ($item = array_shift($tree)) {
      if ($item['link']['in_active_trail']) {
        // If the item is in the active trail, we continue in the subtree.
        $tree = empty($item['below']) ? array() : $item['below'];
        break;
      }
    }
  }

  // Create a single level of links.
  $links = array();
  foreach ($tree as $item) {
    if (!$item['link']['hidden']) {
      // Keyed with the unique mlid to generate classes in theme_links().
      $class = ($item['link']['in_active_trail']) ? ' active-trail' : '';
      if ($item['link']['expanded']) {
        $class .= ' expanded';
      }
      $links['menu-'. $item['link']['mlid'] . $class] = 
tck_menu_link($item);
      if ($item['link']['in_active_trail'] || $item['link']['expanded']) {
        $sublinks = array();
        if ($item['below']) {
          foreach ($item['below'] as $l) {
            $class = ($l['link']['in_active_trail']) ? ' active-trail' : '';
            $sublinks['menu-'. $l['link']['mlid'] . $class] = 
tck_menu_link($l);
          }
          $links['menu-'. $item['link']['mlid'] .'-sublinks sublinks' . 
$class] = array(
            'title' => theme('links', $sublinks),
            'html' => TRUE,
          );
        }
      }
    }
  }
  return $links;
}

Holly Ferree wrote:
> I'm creating a new theme. I want to be able to show the secondary navigation
> links on the left.
>
> For example when you are on admin/build/menu, I want the links in the same
> level (under administer > site building) Blocks, Contact form, ImageCache,
> Menus, Mini panels, Modules, Pages, etc. links to show up on the left.
>
> I have in page.tpl.php:
> <?php print menu_navigation_links('navigation', 2); ?> (using 3 also doesn't
> work...ran out of ideas)
>
> Thanks,
>
> Holly Ferree, Graphic Designer, BFA
> 813.786.0852
> hferree at gmail.com
> http://www.designbyholly.com/
>
>
> _______________________________________________
> consulting mailing list
> consulting at drupal.org
> http://lists.drupal.org/mailman/listinfo/consulting
>   


-- 
Aaron Winborn

Advomatic, LLC
http://advomatic.com/

Drupal Multimedia available in September!
http://www.packtpub.com/create-multimedia-website-with-drupal/book

My blog:
http://aaronwinborn.com/



More information about the consulting mailing list