Drupal - Add class to menu of number of items it contains?
How can I add a class to a menu of the number of items it contains?
My site has a menu that will always have either 7 or 8 items, as one will be regularly be enabled and disabled. I want to style the links slightly differently in either case. If the menu had a class o开发者_如何学Cf the number of items being used this would be easy.
Thanks
The solution is to override theme_menu_item_link, and add the mlid to the actual link.
Drop this snippet into your template.php file and as per usual, replace themeName with your themes name.
<?php
function themeName_menu_item_link($link) {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
if (empty($link['localized_options']['attributes']['class'])) {
$link['localized_options']['attributes']['class'] = 'menu-'. $link['mlid'];
}
else {
$link['localized_options']['attributes']['class'] .= ' menu-'. $link['mlid'];
}
return l($link['title'], $link['href'], $link['localized_options']);
}
?>
for reference ee that link http://adaptivethemes.com/how-to-add-unique-classes-to-drupal-menus
My Reards
精彩评论