I don't think this is hard at all but beeing a beginner at PHP and Drupal I need some help to do this.
I want to be able to add classes to my navigation elements that are outputted with this code:
function mytheme_menu_link__menu_block__1($variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#localized_options']['attributes']['title'] != 'misc' && $element['#localized_options']['attributes']['title'] != 'something') {
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
if ($element['#original_link']['in_active_trail'] == 0) {
$output = ''.$element['#title'].'';
}
else {
$output = ''.$element['#title'].'';
}
$link = l($output, $element['#href'], array('html' => TRUE));
return $link;
}
else {
return '';
}
}
If the menu item is active, it should have class X, otherwise class Y. Could someone explain how I add this?
------------------------- Correct Answer -------------------------------
Here is the correct code that longboardnode helped me come up with.
function mytheme_menu_link__menu_block__1($variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#localized_options']['attributes']['title'] != 'misc' && $element['#localized_options']['attributes']['title'] != 'something') {
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
if ($element['#original_link']['in_active_trail'] == 0) {
$output = $element['#title'];
$class = 'activeClass';
}
else {
$output = $element['#title'];
$class = 'otherClass';
}
$link = l($output, $element['#href'], array('attributes' => array('class' => array($class)), 'html' => TRUE));
return $link;
}
else {
return '';
}
}