Hi guys,

i need a unique menu-item-ID for each menu-item, so i can theme each item individual. I found the following Code and pasted it in my template.php:

function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty($extra_class)) {
    $class .= ' '. $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active-trail';
  }
 
  // Add unique identifier
  static $item_id = 0;
  $item_id += 1; 
  $id .= 'menu-item-' . $item_id;
  // Add semi-unique class
  $class .= ' ' . preg_replace("/[^a-zA-Z0-9]/", "", strip_tags($link));
  return '<li class="'. $class .'" id="' . $id . '">'. $link . $menu ."</li>\n";
} 

With this script i receive a css-id like "menu-item-[number-increment] - so far so good.

The Problem is when i log in. Cause then the ID changes and i dunno why. May be cause there is another Menu rendered in the back. Anyhow - menu-item-3 switches to menu-item-9, and that sucks.

I also can't use the item-name for the unique-styling, cause the page will be multilingual.

Is there any unique menu-item-id that i can receive over phptemplate_menu_item()? Or any other solution?

Thanks in advance
Fab

Comments

stone_d’s picture

ok - this solved all my propblems:

http://drupal.org/project/menu_attributes

YEAH!