开发者

theme_links for aliased pages

开发者 https://www.devze.com 2023-03-26 04:02 出处:网络
For the sake of simplicity, let\'s say I just want to add the \'active\' class to all links within the main menu.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消