The 6.x-1.x branch only works with primary and secondary links.

To add this functionality for menus other than primary and secondary links you can add this to your template.php file in your theme.

/**
 * Generate the HTML output for a menu item and submenu.
 *
 * @ingroup themeable
 */
function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty($extra_class)) {
    $class .= ' '. $extra_class;
  }

  $link_array = explode('href="', $link);
  $link_array = explode('"', $link_array[1]);
  $link_path = trim($link_array[0], '/');
  $current_path = drupal_get_path_alias($_GET['q']);
	
  if (substr($current_path, 0, strlen($link_path)) == $link_path) {
    $in_active_trail = TRUE;
  }

  if ($in_active_trail) {
    $class .= ' active-trail';
  }
  return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
}

Credits: this snippet is provided by redndahead

Comments

squarecandy’s picture

Hey - thanks seriousmatters! This was perfect for what I need and I much prefer this to another module anyways.

Here's my modified code that allows for 2 levels of menu, so for example if you have a menu like thus:

about
press
    press releases
    press kits
    other press stuff
contact

and a url of /press/press-releases/my-individual-page

I wanted press and press releases to both be in the active trail but not press kits, etc...


/**
 * Generate the HTML output for a menu item and submenu.
 *
 * @ingroup themeable
 */
function redpoppy_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty($extra_class)) {
    $class .= ' '. $extra_class;
  }

  $link_array = explode('href="', $link);
  $link_array = explode('"', $link_array[1]);
  $link_path = trim($link_array[0], '/');
  $link_path_parts = explode('/', $link_path);
  $current_path = drupal_get_path_alias($_GET['q']);
  $leaf = strpos($class,'leaf');
    
  if (substr($current_path, 0, strlen($link_path)) == $link_path) {
    $in_active_trail = TRUE;
  }
  if ( ( substr($current_path, 0, strlen($link_path_parts[0])) == $link_path_parts[0] ) && ( $leaf === FALSE ) ) {
     $in_active_trail = TRUE;
  }

  if ($in_active_trail) {
    $class .= ' active-trail';
  }
  return '<li class="'. $class .'">'. $link . $menu .'</li>';
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

add credits to original provider of the code