Return to Snippet

Revision: 13210
at April 14, 2009 13:15 by zachharkey


Initial Code
/**
 * Theme override for theme_menu_item()
 */
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-custom-id-' . $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";
}

Initial URL
http://drupal.org/node/310356#comment-1210124

Initial Description
Place the following function in your theme's template.php

Initial Title
Add unique IDs to Drupal menu items

Initial Tags
drupal

Initial Language
PHP