menu_navigation_links

includes/menu.inc, line 1260

Versions
6 – 7
menu_navigation_links($menu_name, $level = 0)

Return an array of links for a navigation menu.

Parameters

$menu_name The name of the menu.

$level Optional, the depth of the menu to be returned.

Return value

An array of links of the specified menu and level.

Related topics

▾ 2 functions call menu_navigation_links()

menu_primary_links in includes/menu.inc
Return an array of links to be rendered as the Primary links.
menu_secondary_links in includes/menu.inc
Return an array of links to be rendered as the Secondary links.

Code

<?php
function 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']) {
      $class = '';
      $l = $item['link']['localized_options'];
      $l['href'] = $item['link']['href'];
      $l['title'] = $item['link']['title'];
      if ($item['link']['in_active_trail']) {
        $class = ' active-trail';
      }
      // Keyed with the unique mlid to generate classes in theme_links().
      $links['menu-'. $item['link']['mlid'] . $class] = $l;
    }
  }
  return $links;
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.