I've searched and found variations of this question but I've never found an answer that seemed to work. I need to add a class to the <li>
elements, currently the main menu is rendered like this:
print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'slidemenu',
'class' => array(
'links',
'inline',
'clearfix'
)
),
'heading' => t('')
));
As far as I can tell, this only sets up the <ul>
element of the main menu, so I was wondering if there's a way to edit the attributes of the 'links'
part.
---EDIT---
Alright, I think I solved it. Apparently you can use theme_links__system_main_menu
in templates to override the whole thing. I ended up doing this:
function mytheme_links__system_main_menu($variables) {
$html = '<div id="mainmenu">';
$html .= ' <ul id="slidemenu" class="clearfix">';
static $linkClass = 1;
foreach ($variables['links'] as $link) {
$html .= '<li class="themastyle' . $linkClass . '">' . l($link['title'], $link['href'], $link) . '</li>';
++$linkClass;
}
$html .= ' </ul>';
$html .= '</div>';
return $html;
}
Not entirely sure if this is correct Drupal, though it did solve my issue!