I've been fiddling around with drupal theming quite succesfully (or at least, that's what i think), but when I tried to inject css coding to the primary links menu to customize it as i generally do via html+css, i hit a wall.
I have been able to apply css styles to divs, links and text, but I would like to customize the primary (and secondary) links menus much more, perhaps with some css sprite menu techniques, but while remaining drupal-compliant and using as much of drupal's own php in the process. or if i 开发者_开发技巧really have to rewrite some code, i don't mind, though i am not quite the programmer yet.
i have been around several sites but i haven't anything particularly useful, so if anyone can point me to the right direction, i will be quite grateful.
thanx in advance.
You can add a id-like class for each menu item - add this function in your template.php
function mythemename_menu_item_link($link) {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
// LOOK HERE
// add a key for main menu items, so we can theme each item in a different way
// add this class only for a specific menu
if ($link['menu_name'] == 'menu-menu-mymenu') {
if ($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']);
}
This code can be cleaner, but i've added more lines so you can read it better.
if I understand your question correctly you will like to add a custom class/id to you menu . This can be done by overriding the theme_menu_tree for a given menu. I do this for my main menu by adding the following to my template.php file:
function THEMENAME_menu_tree__main_menu($variables){
return '<ul class="menu main-menu">' . $variables['tree'] . '</ul>';
}
hope this helps.
You should also have a look at the themer module, which gives you suggestion for template functions and more.
cheers, Jørgen
精彩评论