menu_primary_links
- Versions
- 4.7 – 5
menu_primary_links($start_level= 1,$pid= 0)- 6
menu_primary_links()
Returns an array containing the primary links. Can optionally descend from the root of the Primary links menu towards the current node for a specified number of levels and return that submenu. Used to generate a primary/secondary menu from different levels of one menu.
Parameters
$start_level This optional parameter can be used to retrieve a context-sensitive array of links at $start_level levels deep into the Primary links menu. The default is to return the top-level links.
$pid The parent menu ID from which to search for children. Defaults to the menu_primary_menu setting.
Return value
An array containing the themed links as the values. The keys of the array contain some extra encoded information about the results. The format of the key is {level}-{num}{-active}. level is the depth within the menu tree of this list. num is the number within this array, used only to make the key unique. -active is appended if this element is in the active trail.
Related topics
Code
includes/menu.inc, line 818
<?php
function menu_primary_links($start_level = 1, $pid = 0) {
if (!module_exist('menu')) {
return NULL;
}
if (!$pid) {
$pid = variable_get('menu_primary_menu', 0);
}
if (!$pid) {
return NULL;
}
if ($start_level < 1) {
$start_level = 1;
}
if ($start_level > 1) {
$trail = _menu_get_active_trail_in_submenu($pid);
if (!$trail) {
return NULL;
}
else {
$pid = $trail[$start_level - 1];
}
}
$menu = menu_get_menu();
$links = array();
if ($pid && is_array($menu['visible'][$pid]) && isset($menu['visible'][$pid]['children'])) {
$count = 1;
foreach ($menu['visible'][$pid]['children'] as $cid) {
$index = "menu-$start_level-$count";
if (menu_in_active_trail_in_submenu($cid, $pid)) {
$index .= "-active";
}
$links[$index] = menu_item_link($cid);
$count++;
}
}
// Special case - provide link to admin/menu if primary links is empty.
if (empty($links) && $start_level == 1 && $pid == variable_get('menu_primary_menu', 0) && user_access('administer menu')) {
$links['1-1'] = l(t('edit primary links'),'admin/menu');
}
return $links;
}
?>Login or register to post comments 