how to get all the menu items below a certain parent in drupal?

前端 未结 5 1757
醉梦人生
醉梦人生 2021-02-01 23:32

I really only need the mlid and title text for the first level below a certain menu item. Here\'s what I\'m doing at the moment. (It works, but I suspect there may be a more dru

5条回答
  •  无人共我
    2021-02-02 00:16

    I use this : Just add your path and eventualy the menu and it will give you the child.

    function MY_MODULE_submenu_tree_all_data($path, $menu = 'main-menu', $curr_level = 0,          $rebuilt_path='', $childtree = array()) {
    $tree = menu_tree_all_data($menu);
    $args = explode('/', $path);
    
    $rebuilt_path = empty($rebuilt_path) ? $args[$curr_level] : $rebuilt_path . '/' .  $args[$curr_level];
    
    foreach ($tree as $branch) {
        if ($branch['link']['link_path'] == $rebuilt_path) {
            $childtree = $branch['below'];
            if ($rebuilt_path != $path) {
                $curr_level++;
                MY_MODULE_submenu_tree_all_data($path, $menu, $curr_level, $rebuilt_path, $childtree);
            }
        }
    }
    
    $items = array();
    foreach ($childtree as $child) {
        $items[] = l($child['link']['title'], $child['link']['link_path']);
    }
    
        return theme('item_list', array('items' => $items, 'attributes' => array(), 'type' => 'ul'));
    
    }
    

提交回复
热议问题