北漂IT民工 的博客

Drupal 菜单的读取方法

1. 通过menu_tree_all_data来读取相应的菜单项

primary-links来读取基本菜单。

也可以读取自定义的菜单。

2. 通过$m[‘below’]来得到是不是有子菜单




    <?php


    $i = 0;


    $menuItems = menu_tree_all_data(‘primary-links’);


    foreach($menuItems as $key => $m):


    ?>




  • <?php


    $href = drupal_get_path_alias($m[‘link’][‘link_path’]);


    $newhref = $href == ‘/‘ ? $href : ‘/‘ . $href;


    $isactive = is_active_menu($newhref);


    if ($isactive) {


    print ““;


    } else {


    print ““;


    }


    if ($isactive) {


    $cursubmenu = $m[‘below’];


    $cursubmenunode = $m;


    }


    if ($m[‘below’]) {


    ?>





    .





    <?php


    foreach($m[‘below’] as $k => $v) {


    $a = $dir . drupal_get_path_alias($v[‘link’][‘link_path’]);



    }


    ?>





    <?php


    }


    $i++;


    ?>



    <?php endforeach; ?>