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 |
Jump to:
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
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
> 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
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
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
can someone please help?
#6
+1
#7
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
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
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
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
Thanks. Committed the explanation of the last follow-up along with a complete overhaul of README.txt.
#12
Automatically closed -- issue fixed for 2 weeks with no activity.
#13
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
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
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
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
rohnjeynolds,
This is just what I needed. Thanks, you saved me headaches! I can sleep better tonight:
Results: http://www.spacefoundation.org/education
<(-_-)>
#18
ultrus, can I ask what you used for the slideshow on the front page??
Thanks.
#19
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:
Hope this get the cogs turning!
Best regards,
Chris
#20
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.