By beertje on
hi there,
I need to assign a menu item to a group of nodes, currently we have something like this in node.tpl.php:
switch($type) {
case 'story': {
if ($node->taxonomy[1]) {
menu_set_active_item('node/5');
drupal_set_breadcrumb(array(
l(t('Home'), NULL),
l(t('Section1'), 'section1'),
l(t('News'), 'section1/news')
));
} elseif ($node->taxonomy[2]) {
menu_set_active_item('node/28');
drupal_set_breadcrumb(array(
l(t('Home'), NULL),
l(t('Section2'), 'section2'),
l(t('News'), 'section2/news')
));
}
break;
}
}
This has the desired effect of making the right menu item active for a group of nodes, but causes other problems since the active node is changed. Does anybody perhaps know a better way to do this? Basicly all I want to do is to make a certain menu item active for a node based on its type and term, I've tried lots of things but so far the intrusive menu_set_active_item is the only option that worked.
Comments
just to clarify, by "assign
just to clarify, by "assign a menu item to a group of nodes" i assume you mean that you want a CSS hook to be added to a given menu item at multiple URLs.
the way i tend to end up doing this is by using consistent path aliases, implementing a custom version of theme_menu_links (Drupal 5; haven't researched the best way to port to 6 yet), and then within that function adding classes based on the path aliases as appropriate.
so for example, i can analyze the query, and add a class to my
<a>if the path starts with 'section1'.i know that's vague and D5-specific, but hopefully it gives you some ideas.
If that would work that
If that would work that would be ok. The biggest problem though is that there are multiple submenu's that are defined by drupal or not in the html depending on where you are on the site. So I need a way to tell drupal what the current path is, at least that is the solution that worked so far. If only there was a way to do it without messing with the content...
Basicly this is what I want to do: let's say we have node/50, node/51 and node/5, where node/5 has the correct active menu item/path. I need some way to tell drupal to use the same menu item/path for node/50 and node/51 (and all simular nodes).
--
jb
well you can always print a
well you can always print a specific menu -- looks like in Drupal 6 you can even specify the name of the menu as opposed to the ID, using the menu_tree function. sounds like that should help.
No that doesn't work, the
No that doesn't work, the primary links menu (where the submenu I want is located) is already visible, only the right submenu is not collapsed (and thus not visible) on the pages I want it to be
--
jb
OK, i'm not sure i
OK, i'm not sure i understand exactly what you're going for, but i'd just recommend spending some time on the menu system section of the API site.
Thank you for your support,
Thank you for your support, I will (and already did, but it never hurds to give something a second look).
For now the node hierarchy module looks like a partial alternative, well kind off anyway ;)
If somebody knows a way to tell drupal what menu item to 'activate' I still would love to hear about it, since this is basicly all I need.
--
jb
From Drupal 6, the active
From Drupal 6, the active trail only gets assigned to the navigation menu. A nasty change for developers. So use this for the main site structure and the menu system should handle the rest.
Alan Davison