Hi,

May it be possible to add a link class to a single or just certain menu items in the primary-links?
(e.g. adding class "custom" to the normal output of my home-link in my primary-menu <a class="active" title="Home" href="/hquadrat/node" set="yes">Home</a>?)

hQuadrat

Comments

dman’s picture

Not a graceful way to do 'just one', no, but I suspect you will get the result you want with what I did:

/**
 * Generate the HTML output for a single menu item.
 *
 * implimentation of theme_menu_item()
 *
 * Added an ID for colour theming, 
 * and tag the first and last item with a special class.
 * 'First' and 'Last' are MANUALLY defined as being the 
 * items with weight -10 and 10 respectively
 *
 * @ingroup themeable
 */
function sme_2007_menu_item($mid, $children = '', $leaf = TRUE) {
	$item = menu_get_item($mid);
	$id = 'menu-' . strtolower(preg_replace("/[^A-Za-z0-9]+/", "-", $item['title']));

	// As there's no way to get the ordinal position from here, use the WEIGHT to figure if this is that first or last item.
	if ($item['weight'] == 10) {$class = 'last';}
	if ($item['weight'] == -10) {$class = 'first';}
	$label = "<div class='link $class' id='$id-link' $style>" . menu_item_link($mid) . "</div>";
	return '<li id="' . $id . '" class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . '">' . $label . $children . "</li>";
}

This adds IDs derived from the menu titles to all the LI items in all the menus so you can pick the ones you want to theme.

You can trim the first/last styling bit, but I left it in FYI.

This is a live sample from this site which has fancy colours, AND rounded corners in tricky places in the menu.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/