For the sake of simplicity, let's say I just want to add the 'active' class to all links within the main menu.
The code below works for non-aliased pages. However, when I run a node that has an alias, the active class does not get applied.
I did verify the code was being triggered.
Any thoughts on how to add a class to the main menu links when viewing a node that h开发者_StackOverflow社区as a url alias?
function mytheme_links__system_main_menu(array $variables) {
foreach ($variables['links'] as $key => $link) {
$variables[$key]['attributes']['class'][] = 'active';
}
return theme_links($variables);
}
If you using main menu links you would be better off using the context module instead of writing the code yourself. It will save time and headache of testing and allow you and your client to edit the the active links through a user interface instead of hard-coding the classes.
Check it out: http://drupal.org/project/context
精彩评论