Community Documentation

Isolate a specific menu item with $mid

Last updated August 26, 2009. Created by MikeyLikesIt on December 7, 2007.
Edited by ronald_istos, add1sun. Log in to edit this page.

This is an additional tweak to the HowTo: Have "first" and "last" classes on menu blocks code.

Sometimes I have the need to style just a single item in a menu (use a different color or background for that item specifically). By adding the $mid into the class array for each list item, I have complete control over this with CSS.

My modified function looks like this:

<?php
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE, $extraclass = '') {
  return
'<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . ($extraclass ? ' ' . $extraclass : '') . ' mid-' . $mid . '">'. menu_item_link($mid, TRUE, $extraclass) . $children ."</li>\n";
}
?>

All I added is ". ' mid-' . $mid", and didn't bother with conditionals since $mid is always defined.

In the CSS I use a selector like #header .mid-123 to isolate the menu item as used in the header, etc. Works great.

About this page

Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here