Hi, I'm sorry if this question is a pretty basic one, I've been charged with making a website for our company but haven't got a huge amount of experience in these things!

I've managed to cobble together a half decent menu system using modified versions of nokoala and nice_menus, but I'd like to make it such that the parent nodes (which are shown all the time in a horizontal bar at the top of the site) are highlighted when one of their children is active. Could anybody shed some light on how to do this? I presume it has something to do with the css files.

If you want to have a look at the site, its at www.masonryarch.com

Thanks, Tom

Comments

johnnybegood’s picture

Add the code below to your template.php, this is an override function. I've used it when I created the Aberdeen theme and it does what it says on the tin ;)

It provides you a lot of flexibility for your CSS.

/**
 * Override theme_links to include class active in parent item when child item is active.
 */
function phptemplate_links($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = '';

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
        $class = $key;
      }
      else {
        $link['attributes']['class'] = $key;
        $class = $key;
      }

      // Add first and last classes to the list of links to help out themers.
      $extra_class = '';
      if ($i == 1) {
        $extra_class .= 'first ';
      }
      if ($i == $num_links) {
        $extra_class .= 'last ';
      }
	  
	 
	  // Add class active to active li 
	  $current = '';
	  if (strstr($class, 'active')) {
	    $current = ' active';
	  }	

	  $output .= '<li class="'. $extra_class . $class . $current .'">';
	  
	  // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

      if (isset($link['href'])) {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}
Dr_Tom’s picture

Thanks...I'll give it a go now.

Dr_Tom’s picture

As usual ,a server malfunction has scuppered my chance of doing anything to the website...but I'll try soon :-)

fekimoki’s picture

Any chance for modification of this function to show the sub menus?

jody lynn’s picture

Thanks JBGood. I needed this too. This will save me a ton of time.

--Zivtech--