5

I need to know how to add extra class to a perticular menu.For example i have custom menu "menu-header-let",This menu is rendering like below,

<ul class="menu"><li class="leaf first"><a title="Redirecting to Help Page" href="/vsv/content1">Help</a></li>
<li class="leaf"><a title="" href="/vsv/content1">Home</a></li>
<li class="leaf last"><a title="" href="/vsv/content1">home2</a></li>
</ul>

Now i want add extra class to the ul like below

   <ul class="header-top-menu">

I used phptemplate_menu_tree(), but i need different class for each custom menu.If is override menu theme and adding same class for all custom menu.

I have no idea how to add different class when different custom menu renders in drupal.

please help me.

3 Answers 3

4

Well, the code in tutorial that beth mentioned has bugs and does not work. The best solution I've found up to now is this:

<?php
function YOUR_THEME_menu_tree($tree) {
  if (preg_match('/A unique string in your menu/', $tree)) {
      return '<ul class="header-top-menu">' . $tree . '</ul>';
  } else {
    return '<ul class="menu">'. $tree .'</ul>';
  } 
}
?>

You can use any unique path or link title as string to identify the menu. This solution was inspired by a comment in the cited tutorial.

1
  • 1
    You're right, the tutorial contains an infinite loop (see this question).
    – beth
    Commented Dec 21, 2012 at 22:14
0

There's a tutorial just for you: http://programmingbulls.com/complete-drupal-6-menu-theming

0

I should agree that theming of menu items in Drupal sucks.

There is a module Menu Attributes which does just that. You can also add Id,Name, Target, Rel,Class,Style,Accesskey attributes to the particular menus.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.