Having menu highlighted when I visit individual nodes

Julien PHAM - October 31, 2008 - 12:16
Project:Menu Trails
Version:6.x-1.0
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi,

Menu trails is intended to do this, isn't it? Cannot figure out how I can make it work in my website.
Let's say I have a menu item, name A. I would like that when I visit an individual node of the taxonomy X, the menu A highlights.

How can I achieve this?

btw if my menus are split up in several blocks, how can I get menu trail to work on all blocks?

Thanks

#1

akahn - November 5, 2008 - 19:11

For your first question, I think the answer is that you need to write CSS to style your menu how you want. Trying adding li.active-trail a, li a.active { color: red; } to your stylesheet, for example.

For your second question, it looks like you can only use this module with one menu.

#2

-Anti- - November 5, 2008 - 19:34

> Menu trails is intended to do this, isn't it?

The Menutrails module fixes the unwanted/broken core behaviour (ie. the menu de-highlights when a node is viewed). It also does quite a good job (but not perfect) of fixing the core breadcrumbs too.

I have it working on my site, so you just need to keep playing with it; it does work.

As suggested, you need to get the core active-trail highlighting working in your theme first. Not all D6 themes support this anyway, and to make matters worse, the 6.6 upgrade broke many themes which did support it (the devs fixed a syntax error with the active-menu html, but this meant that many themes have to now change their style.css file).

The suggested css is correct.

Then, as advised in the module's readme, you need to add this to your theme's template.php file:

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) { // what function is active?
    case 'page': // page is where menu comes into play
      // set the primary links
      $vars['primary_links'] = menutrails_primary_links(1);
      // you may want to also override secondary_links
      $vars['secondary_links'] = menutrails_primary_links(2);
      break;
  }
}

> It looks like you can only use this module with one menu

I thought that too, but I'm not so sure. It think you specify default preferences so that if there is a confusing or conflicting situation between menus, the script can make a decision to highlight the most important one. But I think it actually tries to maintain the active-trail on all menus. Not sure though.

#3

dtabach - November 27, 2008 - 15:37

Is this addition to template.php still required for 6.x versions? The readme for 6.x-1.0 just says "Menutrails.module contains a built-in override for theme_links, which is necessary to add the 'active' class to the containing <li> for each menu item", but no code to be inserted in template.php is included.

#4

tevih - January 6, 2009 - 19:01

I'm confused about that, too. The readme does not have any code in it, either.

If a secondary menu is set to have a parent item from, say, "Primary Navigation", are all the items in the secondary menu links to supposed allow menu trails to add the new class name? This isn't working for me.

Using Drupal 6.8

#5

tevih - January 8, 2009 - 02:43

can someone please help?

#6

neek - January 11, 2009 - 01:38

+1

#7

Guffnstuff - April 3, 2009 - 08:02

I'm also confused about whether I need to install a snippet of code somewhere.

I'm using Drupal 6.10 with Garland theme on Windows XP SP2 with xampp - localhost and I've tried both the 6.x-1.0 and 6.x-1.x-dev (2009-Feb-03) versions of Menu Trails and I can't get the appropriate menu items to display with the appropriate style (bold, in this case).

I've viewed source and the assigned parent menu item in question is tagged as
li class="leaf active-trail", which I assume is the way it's supposed to be, and yet it doesn't appear bold.

I'm also using:
- Custom breadcrumbs
- Pathauto
- Page Title
which all work for me.

Any ideas?

I have wondered whether it might be a problem with the Navigation menu - I haven't tried MT with the Primary Links menu coz i don't use that. I've assumed that since Menu Trails admin interface allows me to select the navigation menu that it's meant to work with MT.

#8

pulse8 - April 13, 2009 - 18:17

Add me to the confused lot. Mine adds the active trail bit to the menu item, but doesn't add an active class. I'm not sure how this all functions together.

#9

karel3s - April 15, 2009 - 12:36

Hi,

Try adding the css code below to your stylesheet. This is just an example for the default Garland theme.

ul.primary-links li.active-trail a{
background:transparent url(images/bg-navigation-item-hover.png) no-repeat scroll 50% 0;
color:#FFFFFF;
}

Your primary links are not highlighted by default because in the Garland theme the 'active' class is assigned to the a tag while this module adds a class of 'active-trail' to the li tag.

Hope this helps.

Regards,

Karel

#10

eojthebrave - April 16, 2009 - 22:56

For those confused about the theme function in the README.txt file, this is no longer present in the 6.x version of the module, and is no longer needed to use the module. The 5.x version of the module required you to override theme_links() in your template.php file but the 6.x version overrides it automatically, see menutrails.module phptemplate_links()

Note that if your Drupal 6 theme already overrides the theme_links() function in the template.php file you will need to manually reconcile the differences between your THEMENAME_links() and menutrails phptemplate_links() functions. The final result should live in THEMENAME_links() in your template.php file.

#11

sun - July 24, 2009 - 15:33
Status:active» fixed

Thanks. Committed the explanation of the last follow-up along with a complete overhaul of README.txt.

#12

System Message - August 7, 2009 - 15:40
Status:fixed» closed

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

#13

libeco - August 10, 2009 - 19:18

Drupal sets both the classes active and active-trail for active menu items, Menu Trails module only sets active-trail as the class. It took me a while to figure out why it wasn't working. Perhaps this 'problem' should be added to the readme?

#14

rohnjeynolds - September 6, 2009 - 15:17

I was able to make MenuTrails work correctly in Drupal 6 with my Zen subtheme by copying the module's phptemplate_links() function to my subtheme's template.php file, renaming it after my subtheme (e.g. mytheme_links), fixing one line as described below, and reloading the theme registry.

//if (strpos($link['attributes']['class'], 'active-trail') !== FALSE && strpos($class, 'active') === FALSE) {
if (strpos($class, 'active-trail') !== FALSE && strpos($link['attributes']['class'], 'active') === FALSE) {

In other words, reverse $class and $link['attributes']['class'] in the two conditions. I don't know if this is a bug in MenuTrails, Zen or just a conflict between the two.

Further, I don't know if this is a good or correct solution, or whether will work for everyone, but it worked for me. I came to this after noticing that 'active-trail' CSS class was appearing correctly on the containing <li> but that the <a> tag wasn't getting the needed 'active' class.

#15

rohnjeynolds - September 6, 2009 - 20:50

A follow-up observation: It seems to me that there are many cases when overriding theme_links() -- whether you're using MenuTrails' built-in override function or your own -- just isn't helpful. For example, I have a site where the menu I'm using for MenuTrails isn't primary links or secondary links, but my own menu that I'm rendering in a block. In this case, I don't believe theme_links() is called at all; rather, theme_menu_item() and theme_menu_item_link() are. So I was able to get positive results by writing this variation on theme_menu_item_link() in my template.php file, and reloading the theme registry:

function mytheme_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }

  // This is the new code I added to make MenuTrails behave
  if ($link['in_active_trail']) {
    if (empty($link['localized_options']['attributes']['class'])) {
      $link['localized_options']['attributes']['class'] = 'active';
    } else {
      $link['localized_options']['attributes']['class'] .= ' active';
    }
  }
  // end new code

  return l($link['title'], $link['href'], $link['localized_options']);
}

Moreover, if you were assigning MenuTrails to use primary or secondary links, but were opting to render those menus in blocks rather than by calling printing $primary_links or $secondary_links in your template files, I think (but don't know for sure) that you would need to override theme_menu_item_link(), as described above, instead of overriding theme_links().

#16

Delicious Creative - September 15, 2009 - 13:05

I was able to get this working in a Zen subtheme without having to change anything in my template.php file.

As it's said in #14 above, the module adds a css class of "active-trail" to the <li>, but not the <a> tag, but with adding in a little extra css that's easily remedied.

I was using this for some menu items in my primary links so I added this to my stylesheet:

#primary li.active-trail a
{
color: #000;
}

That produced the results I was after.

DC

--------------------------------
Delicious Creative
Liverpool Web Design, Video, Audio, & Creative Services
http://www.deliciouscreative.com

#17

ultrus - September 25, 2009 - 19:17

rohnjeynolds,
This is just what I needed. Thanks, you saved me headaches! I can sleep better tonight:
Results: http://www.spacefoundation.org/education

<(-_-)>

#18

-Anti- - September 27, 2009 - 18:47

ultrus, can I ask what you used for the slideshow on the front page??

Thanks.

#19

ultrus - September 27, 2009 - 19:35

Anti,
The Flash slide show is a custom Flash piece I built that reads a modified RSS/XML feed (controlled partly by a view, and and rss template file) to reference data for what slides/links/summaries to load. Image, summary, and sort order fields were added to key content types so that the education staff could control the slide show, and also have images to feature at the top of different website areas. The flash slide show itself is loaded in a block to display on the home page. JavaScript required to deal with the Flash was added to the theme .info file of the site.

The solution isn't perfect yet, but I hope to share as I learn more about module creation, and get permission from my office (which should not be an issue since we're all about contributing to the community). You can watch for updates on my blog: http://www.christopherstevens.cc/blog . ETA for a module is unknown (I'm still at newbish/intermediate Drupal skill).

I followed these steps to make it work:

  1. Figure out the image/slide show dimensions for your site.
  2. Add feature image, feature summary, feature slide show order, and weather or not to feature in slide show fields, shared between all content types you would feature in a slide show. In the case of the Education site, nodes like 'links' are NOT featured because they do not have their own page (just listed in a single page view).
  3. Get Drupal to produce an xml feed. This one was tough for me, but got something to work by creating an RSS feed view, then giving it a custom theme.
  4. Get Flash to read parse the XML, and adjust image source urls and links to make them load in Flash.
  5. Create a Flash XML slide show.

Hope this get the cogs turning!

Best regards,

Chris

#20

-Anti- - September 27, 2009 - 21:01

Thanks for your verbose reply.
I'll certainly mull it over and take a look at your blog!
Good luck with the module... your slideshow looks great.

 
 

Drupal is a registered trademark of Dries Buytaert.