0
votes

I want to add #ID or Class items to each individual list item, something like 'menu-item-1', 'menu-item-2', etc.? Should I do this in template.tpl.php, or directly change the output in page.tpl.php?

My current coding is adapted to work for dropdown (tree) menu.

Thanks for help!

 <div id="nav"><!--nav-->
      <?php
         $menu_name = variable_get('menu_main_links_source', 'main-menu');
         $tree = menu_tree($menu_name);
         print drupal_render($tree); 
       ?>           
 </div><!--/nav-->
1

1 Answers

0
votes

You can use the menu attributes module, which lets you add most of common attributes as ID, Title, Class and stuff from administrator to your menu items without theming.

Besides you can use the theme function like this:

print theme('links__system_main_menu', array(
    'links' => $main_menu,
    'attributes' => array(
      'class' => array('links', 'clearfix'),
      'id' => 'menu' 
     ),
    'heading' => array(
      'text' => t('Main menu'),
      'level' => 'h2',
      'class' => array('element-invisible'),
    ),
));

And Drupal will add unique classes to your menu list items as well.