Home > Drupal Themes making > Code for active primary link in drupal.

Code for active primary link in drupal.


In the page template.php in sites/all/themes/yourthemes paste the following codes:

function new_primary_links($start_level = 1, $pid = 0) {
if (!module_exists(‘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-$pid”;
if (menu_in_active_trail_in_submenu($cid, $pid)) {
$index .= “-active active”; // **** HERE’S THE CHANGE
}
$links[$index] = menu_item_link($cid, FALSE);
$count++;
}
}
return $links;
}

After that,in page.tpl.php paste the following codes:

<?php
print theme(‘links’, $primary_links);
?>

For more help: http://drupal.org/

Categories: Drupal Themes making
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment