Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The 6.x-1.x branch only works with primary and secondary links.
To add this functionality for menus other than primary and secondary links you can add this to your template.php file in your theme.
/**
* Generate the HTML output for a menu item and submenu.
*
* @ingroup themeable
*/
function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
if (!empty($extra_class)) {
$class .= ' '. $extra_class;
}
$link_array = explode('href="', $link);
$link_array = explode('"', $link_array[1]);
$link_path = trim($link_array[0], '/');
$current_path = drupal_get_path_alias($_GET['q']);
if (substr($current_path, 0, strlen($link_path)) == $link_path) {
$in_active_trail = TRUE;
}
if ($in_active_trail) {
$class .= ' active-trail';
}
return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
}
Credits: this snippet is provided by redndahead
Comments
Comment #1
squarecandy CreditAttribution: squarecandy commentedHey - thanks seriousmatters! This was perfect for what I need and I much prefer this to another module anyways.
Here's my modified code that allows for 2 levels of menu, so for example if you have a menu like thus:
and a url of /press/press-releases/my-individual-page
I wanted press and press releases to both be in the active trail but not press kits, etc...
Comment #2.0
(not verified) CreditAttribution: commentedadd credits to original provider of the code