How can count the children of Drupal's main menu?
Is there a possibility to get the number of children of the main menu in Drupal (7)? I need to implement it in this part of the hook:
if($item_id < NUMBER OF MAIN MENU CHILDS) {
return '<li id="cus开发者_开发技巧tom-menu-item-id-' . (++$item_id) . '"' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
else {
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
This menu doesn't contain any subitems, but with children I mean every 'li' attribute.
You can use menu_tree_page_data:
$num_top_level_children = count(menu_tree_page_data('main-menu'));
精彩评论