Normally it's useful to have the active menu item marked, eg. by class="active". With this module it is only the case for the menu link itself. In order to style the surrounding box ( li ) it would be usefull to have it marked as well.
Find below my solution trough overriding of the theme function:
function pdda_nice_menu_build($menu) {
$output = '';
foreach ($menu as $menu_item) {
$mlid = $menu_item['link']['mlid'];
if ($menu_item['link']['hidden'] == 0) {
$clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
$clean_path = str_replace('/', '-', $clean_path);
$path_class = 'menu-path-'. $clean_path;
// ******* included check if active item *******
$active_class = ($menu_item['link']['href'] == $_GET['q'] || ($menu_item['link']['href'] == '<front>' && drupal_is_front_page())) ? ' active ' : '';
if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {
$children = theme('nice_menu_build', $menu_item['below']);
$parent_class = $children ? 'menuparent ' : '';
// ******* included $active_class here: *******
$output .= '<li id="menu-'. $mlid .'" class="'. $parent_class . $path_class . $active_class .'">'. theme('menu_item_link', $menu_item['link']);
if ($children) {
$output .= '<ul>';
$output .= $children;
$output .= "</ul>\n";
}
$output .= "</li>\n";
}
else {
// ******* included $active_class here: *******
$output .= '<li id="menu-'. $mlid .'" class="'. $path_class . $active_class .'">'. theme('menu_item_link', $menu_item['link']) .'</li>'."\n";
}
}
}
return $output;
}
Comments
Comment #1
globetrotter commentedsorry, forgot to mention:
while overriding the theme function is ok, it would be nicer to have this detail in the module core.
:)
Comment #2
add1sun commentedHm, well this is actually what core is doing, so it isn't a limitation of this module per se. Adding another class to the LI should probably work off the same direction as the #219804: Set active menu trail CSS selectors patch. So, we should wait until that patch settles and is in HEAD and then we can look at also adding the "active" class as well.
Patch needs review should only be set if there is actually a patch attached, so I'll reset this to active and to 6.x-2 where this sort of change would go in.
Comment #3
add1sun commentedchanging title to be clear
Comment #4
PMPP commentedNot only the li.active, but also something like:
li.selected a.selected
--- ul
----- li
----- li.selected a.selected
This way one could trace the path till the deepest selected item. That would be of great value to customization of Nice Menu.
Comment #5
add1sun commentedWell the active trail class is already in from the previous issue referenced above. I'd look at a patch to add this to NM, but won't work one up myself.
Comment #6
add1sun commentedComment #7
jnettikThe active-trail link wasn't showing up on the home link for me. Here's a patch that added that for me tested against 2.1
Comment #8
cardpages commentedJust to confirm: Works like a charm!
Comment #9
int_ua commentedComment #11
avpadernoComment #12
astonvictor commentedD7 reached its EOL back in January 2025, and there is no active release for D7 for this module anymore.
Development or support is not planned for D7. All D7-related issues are marked as outdated in a bunch.