Skip to content

Instantly share code, notes, and snippets.

@abulte
Last active December 25, 2015 05:09
Show Gist options
  • Save abulte/6921997 to your computer and use it in GitHub Desktop.
Save abulte/6921997 to your computer and use it in GitHub Desktop.
Fetch children node from the current menu in Drupal 7
<?php
// requires Menu Node API https://drupal.org/project/menu_node
$children = array();
$trail = menu_get_active_trail();
if (count($trail)) {
$current_item = $trail[count($trail) - 1];
$parameters = array(
'active_trail' => array($current_item['plid']),
'only_active_trail' => FALSE,
'min_depth' => $current_item['depth']+1,
'max_depth' => $current_item['depth']+1,
'conditions' => array('plid' => $current_item['mlid']),
);
$menu_tree_children = menu_build_tree($current_item['menu_name'], $parameters);
foreach ($menu_tree_children as $key => $value) {
$children[] = menu_node_get_node($value['link']['mlid']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment