A
A
anikitin352015-12-30 12:45:41
Drupal
anikitin35, 2015-12-30 12:45:41

How to set id and class to any menu level?

There are two menus: menu_block__1 and menu_block__2.
How can I manually set classes for each menu level?
For example:
first level ul - class "primary",
second level ul - class "secondary"
third level ul - class "last"
I tried these functions:

function THEME_menu_link(array $variables) {
global $_current_menu_depth;
$element = $variables['element'];
$_current_menu_depth = $element['#original_link']['depth'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '' . $output. $sub_menu . "\n";
}
function omega_shop_menu_tree($variables) {
global $_current_menu_depth;
return '
  • ' . $variables['tree'] . '
';
}
}

Doesn't work for expanded menus (always show child elements)
Can anyone suggest a more interesting solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Darkhan Kutzhanov, 2015-01-08
@dark_kz

You can use the menu_attributes module

V
Vladimir, 2015-01-04
@seoyuzer

dhtml-menu, although this module automatically sets each li to its own class, but each menu item has its own unique class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question