I had the typical menu problem which has been discussed plenty of times here:

Given a Primary menu (tab-like menu in header of K2 theme) structure like this:

+ Works
| + Project1
| - Project2
- Search

i wanted "Works" (top-level menu item) to stay highlighted when being on page "Project1".

After unsuccesfully trying all the menu-functions (menu_set_active_item, ...) i found out that it's actually a problem with the K2-theme rather than drupal / the path. K2 will not highlight the menu-item when you're on one of it's subpages. This is extremely odd with search (which redirects q=search to q=search/node) for example.

My solution:

// in k2 -> theme -> template.php
//
function k2_primary( $items = array() )
{
	$output = '<ul class="menu">';

	if (!empty($items))
	{
    	foreach ($items as $k => $item)
    	{
    		if ( substr( $k, -6, 6 ) == 'active' )  // toplevel-item active?
				$item = str_replace( '">', '" class="active">', $item );
    		
			$output .= '<li class="page_item">'. $item .'</li>';
		}
	}
	
	$output .= '</ul>';
	
	return $output;
}

Hope this helps someone.

Comments

barretr’s picture

Kudos for your solution. Works like a charm.