Drupal menu system - tree down one level down

I read various menu functions in Drupal, but there are many of them, and I have come to complete confusion and despair ... Hoping that one of the clever people here can help me ...

Basically, I have four levels for my menu. I am trying to create a tree that is displayed from the second level down.

So, the menu looks like this: LEVEL ONE> Sublevel A> Sublevel I> Sublevel a

I am trying to display a menu tree starting with Sublevel A (i.e. sublevel A> sublevel I> sublevel a)

But I can’t figure out how to do this ... I tried just getting the mlid menu of Sublevel A (in this case 69), and then

<?php print theme_menu_tree(69); ?>

but he just prints "69." Not at all what I expected ...

Does anyone know how to do this?

+5
3

, , afaik .

, , , , :

/**
 * Extract a specific subtree from a menu tree based on a menu link id (mlid)
 *
 * @param array $tree
 *   A menu tree data structure as returned by menu_tree_all_data() or menu_tree_page_data()
 * @param int $mlid
 *   The menu link id of the menu entry for which to return the subtree
 * @return array
 *   The found subtree, or NULL if no entry matched the mlid
 */
function yourModule_menu_get_subtree($tree, $mlid) {
  // Check all top level entries
  foreach ($tree as $key => $element) {
    // Is this the entry we are looking for?
    if ($mlid == $element['link']['mlid'])  {
      // Yes, return while keeping the key
      return array($key => $element);
    }
    else {
      // No, recurse to children, if any
      if ($element['below']) {
        $submatch = yourModule_menu_get_subtree($element['below'], $mlid);
        // Found wanted entry within the children?
        if ($submatch) {
          // Yes, return it and stop looking any further
          return $submatch;
        }
      }
    }
  }
  // No match at all
  return NULL;
}

, , menu_tree_page_data() menu_tree_all_data(), , ( API ). , , mlid. HTML menu_tree_output():

$mlid = 123; // TODO: Replace with logic to determine wanted mlid
$tree = menu_tree_page_data('navigation'); // TODO: Replace 'navigation' with name of menu you're interested in
// Extract subtree
$subtree = yourModule_menu_get_subtree($tree, $mlid);
// Render as HTML menu list
$submenu = menu_tree_output($subtree);

: , / - , , , OP, , , - ...

+11

, . ( , ).

+13

... - - - , .

. c & p.

// will return all menu items under "administration".
print theme('menu_tree_by_path','admin');

// will return links to all node submission forms
print theme('menu_tree_by_path','node/add');

// return the correct menu array by path
function menu_get_mid_by_path($path) {
// oddly, menu_get_item accepts a path, but returns the parent id.
  $menu = menu_get_item(null, $path);
  if (isset($menu['children'])) {
// so we have to extract the mid for theme_menu_tree from one of the child items
    if ($pid = end($menu['children'])) {
      $menu = menu_get_item($pid);
      return $menu['pid'];
    }
  }
}

//theme the crap out of it
function theme_menu_tree_by_path($path) {
  if ($mid = menu_get_mid_by_path($path)) {
    return theme('menu_tree', $mid);
  }
} 
+1

All Articles