Add an icon to menu links
Place this in template.php, and it'll assign a unique id to each of your menu items, allowing you to attach css (and thus icons, jquery, rollovers, etc.) to individual menu items. Very handy!
<?php
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
$link = menu_item_link($mid);
$css_id = strtolower(str_replace(' ', '_', strip_tags($link)));
return '<li id="' . $css_id . '" class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. $link . $children ."</li>\n";
}
?>Then attach the usual css such as
li#my_account a{
background-image:url(../mytotallysweeticons/my_account.png);
}Thanks goes to Nick Lewis for writing the original script - this is a slightly simpler version of that.
For users of the Framework Theme in English
Thanks to SteveJB for the following contribution.
For users of the framework theme (or any theme that by default) adds odd and even classes.
Replace (found at the bottom of the packaged template.php)
function phptemplate_menu_item($mid, $children = '', $leaf = true) {
static $count = 0;
$zebra = ($count % 2) ? 'odd' : 'even';
$count++;
return '<li class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .' ' . $zebra . '">'. menu_item_link($mid) . $children ."</li>\n";
}with
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
static $count = 0;
$zebra = ($count % 2) ? 'odd' : 'even';
$count++;
$link = menu_item_link($mid);
$css_id = strtolower(str_replace(' ', '_', strip_tags($link)));
return '<li id="' . $css_id . '" class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .' ' . $zebra . '">'. menu_item_link($mid) . $children ."</li>\n";
}to keep add and even classes while giving li's their own id.
If you have a language other than English (say, Chinese), then you would have something like the following:
<li id="Chinese-characters" class="leaf">
Hello, thank you for taking
Hello, thank you for taking the time to write this.
Unfortunately, this is not working at all for my website.
I have tried this on the primary, menu, and secondary links.
Any suggestions?
------------------------------------------------------------------------
Personal Advice Website build on Drupal 6: Jamrie.com