I need to theme a menu so that each level has different class in CSS. This needs to be done over template.php and additional code that adds menu level value to your links.
Here is the code you paste in template.php for drupal 7
function template_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
// This example is adds the depth class just for a specific menu. Change 'menu-name' to your menu name.
if ($element['#original_link']['menu_name'] == 'menu-name') {
$element['#attributes']['class'][] = 'level-' . $element['#original_link']['depth'];
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
else {
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
}
and here is for drupal 6
<?php
function phptemplate_menu_item_link($link) {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
if ($link['menu_name'] == 'my-menu-name') { // change my-menu-name for the name of the menu you want the classes in
$link['localized_options']['attributes']['class'] .= ' level-' . $link['depth'];
}
return l($link['title'], $link['href'], $link['localized_options']);
}
?>