1

I am able to add unique ids to menu links by either adding code to my theme's template file or by using a menu module; however, I would like to add a unique id to the ul tag that encapsulates the menu li links. The reason that I would like to implement this is to style the menu as a whole instead of the menu's individual links. My ultimate goal is to take the whole menu and float it to the right in the header-top region of drupal. I am rather new to Drupal so, perhaps there is another way to achieve this?

I originally attempted custom css styles using the skinr module without success. The skinr module was able to move the menu's title to the right, but the menu's links were still located at the left of header-top.

My setup consists of Drupal 7

UPDATE I was able to add a custom CSS class "user-menu" to the user-menu block. Next I added a custom css to mix-and-match-style.css

css code:

.user-menu ul li {
     padding: 0;
     float: right;
}

The css code seems to float: right the menu, but the links are not ordered properly once floated to the right. The correct order of the links should be "My account | Log out". When the list is floated to the right the order changed to: "Log out My account |"

Is that a bug or am I not understanding something?

1 Answer 1

2

You can make use of theme_menu_tree

function theme_menu_tree($variables) {
  return '<ul class="menu">' . $variables['tree'] . '</ul>';
}

http://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_tree/7

You can print this menu tree

template_preprocess_menu_tree

hereis api

Pre process the menu tree OR Call the menu theme to print it as you want. Thats all.

6
  • Am I supposed to change 'tree' to the menu name?
    – dottedquad
    Apr 3, 2012 at 5:06
  • After testing out my question I arrived to the conclusion that I am NOT supposed to change the 'tree to the menu name as doing that throws errors. I am not exactly sure where to go from here to generate unique class or ID names. For example, have that function generate "menu-someuniquenumber" as the ul class or id name.
    – dottedquad
    Apr 3, 2012 at 5:23
  • template_preprocess_menu_tree will help you for sure.
    – niksmac
    Apr 3, 2012 at 5:25
  • Ok, I am relatively new to drupal. I am searching google for a learning tutorial about drupal's api calls for this example, but I am not receiving valuable information. I read over drupal's api and the basic example is there; however, I am still unsure how to get this to work. So far I successfully used theme_menu_tree api.
    – dottedquad
    Apr 3, 2012 at 6:36
  • template_preprocess_menu_tree can be used to alter the menu tree from your template.php file.
    – niksmac
    Apr 3, 2012 at 6:38

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.