Do you know how to do it? Picture illustrates my question:
http://img140.imageshack.us/img140/412/menuqg0.gif

Comments

jody lynn’s picture

In includes/menu.inc:

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

You can override this in your theme's template.php something like

 function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {

  $active = ' ';
    if(menu_get_active_title() == $mid['title']){
	   $active = ' active ';
    }
 	  
  foreach ($children as $cid) {
	  if(menu_get_active_title() == $cid['title']){
	   $active = ' active ';
    }


  return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .$active'">'. menu_item_link($mid) . $children ."</li>\n";
} 

However it will depend on how you're displaying your menu which functions it goes through, so no guarantees

--Zivtech--

Mavros Gatos’s picture

Thank you. And I have another question: is it possible to make two blocks of "Primary+Secondary links".

pvasili@drupal.org’s picture

 $active = ' active ';
    }
}
return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .$active.'">'. menu_item_link($mid) . $children ."</li>\n";
fekimoki’s picture

warning: Invalid argument supplied for foreach() in

CraigBertrand’s picture

Does anyone have working code for this?

I am not a php guru and I stuck this in my template.php but it didn't work.
is this code working or is it something I am doing wrong?

I am trying to style my menu so that when a child link is active then the parent will be active also
that is have the css class "active"

Thanks
----------------------------------------------------
My Site

----------------------------------------------------
CraigBertrand.com

danyg’s picture

It works with drupal path module. Simle solution - I hope it's near the Drupal standard :P
In this case the code is checking if $link_item['path'] is corresponding with the query URL ($_REQUEST['q']).
This is working with only three level deep menustructure, in this path case:
products
products\product1
products\product1\product11
products\product2
products\product2\product21
products\product2\product22
products\product2\product23
products\product3

The nodes have to use the path above.
It gives an extra 'actual' class to '<a>' tag, which can be designed in CSS.

Use this in Your template.php:

function phptemplate_menu_item_link($item, $link_item) {
		$url = drupal_get_path_alias($link_item['path']);
		$active = false;
	if ($url == substr($_REQUEST['q'],0,strrpos($_REQUEST['q'],"/"))) {
		$active = true;
	} elseif ($url == substr($_REQUEST['q'],0,strpos($_REQUEST['q'],"/"))) {
		$active = true;
	}
	$attrib = array();
	if (!empty($item['description'])) {
		$attrib['title'] = $item['description'];
	}
	if ($active === true) {
		$attrib['class'] = 'actual';
	}
	return l(
		$item['title'], 
		$link_item['path'], 
		!empty($attrib) ? $attrib : array(),
		isset($item['query']) ? $item['query'] : NULL);
}
danyg’s picture

Hi,

I was correcting my code. It still uses the path module, but doesn't depends on deep levels of the path.
So You can use: products/subproducts1/subproduct11/product1/product11 stc.
This compare the actual URL and menu item's path and if it can find matching, remark the link with an 'actual' class.

function phptemplate_menu_item_link($item, $link_item) {
// Getting the menu item's path
	$url = drupal_get_path_alias($link_item['path']);
// Getting the actual URL and explode both
	$path = explode("/",$_REQUEST['q']);
	$linkpath = explode("/",$url);
// Checking deep of the menu item's path
	$maxitem = (count($linkpath)-1);
	$active = false;
// Preparing for compare, interlacing the actual path to wanted deep
	$checkpath = "";
	for ($i=0;$i<=$maxitem;$i++) {
		$checkpath .= $path[$i]."/";
	}
// Compare and remark
	if ($url."/" == $checkpath) {
		$active = true;
	}
// Attributes for link
	$attrib = array();
	if (!empty($item['description'])) {
		$attrib['title'] = $item['description'];
	}
	if ($active === true) {
		$attrib['class'] = 'actual';
	}
// Return
	return l(
		$item['title'], 
		$link_item['path'], 
		!empty($attrib) ? $attrib : array(),
		isset($item['query']) ? $item['query'] : NULL);
}