我实际上只需要某个菜单项下面第一级的 mlid 和标题文本。这就是我现在正在做的事情。 (它有效,但我怀疑可能有一种更 drupal 的方式。):
/**
* Get all the children menu items below 'Style Guide' and put them in this format:
* $menu_items[mlid] = 'menu-title'
* @return array
*/
function mymod_get_menu_items() {
$tree = menu_tree_all_data('primary-links');
$branches = $tree['49952 Parent Item 579']['below']; // had to dig for that ugly key
$menu_items = array();
foreach ($branches as $menu_item) {
$menu_items[$menu_item['link']['mlid']] = $menu_item['link']['title'];
}
return $menu_items;
}
有没有?
实际上有一种简单的方法可以通过使用来获取该信息菜单_构建_树() http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_build_tree/7:
// Set $path to the internal Drupal path of the parent or
// to NULL for the current path
$path = 'node/123';
$parent = menu_link_get_preferred($path);
$parameters = array(
'active_trail' => array($parent['plid']),
'only_active_trail' => FALSE,
'min_depth' => $parent['depth']+1,
'max_depth' => $parent['depth']+1,
'conditions' => array('plid' => $parent['mlid']),
);
$children = menu_build_tree($parent['menu_name'], $parameters);
$children
包含您需要的所有信息。menu_build_tree()
还会检查访问或翻译相关的限制,以便您只能获得用户真正应该看到的内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)