I create a theme for a website that has different "zones". I implement that by defining a vocabulary "zones" and a taxonomy term for every zone, and force every content to set a taxonomy term field. So far so good. Now I want that the website visitor can see which part he enters if he clicks on a menu link by styling the menu items differently according to the zone of the content they point to.

Ideally, every menu item has a css-class set with taxonomy-<vocabulary>-<term> or so for every term the linked-to content has. There is a module, Menu attributes, which goes slightly in this direction, but here I have to manually set this for every menu item - not what i want.

Does anybody have an idea how to implement this?

Comments

nevets’s picture

If you mean once you land on the page that will be the active menu item which you can already style.

Add in the context module add you can add a class to the body tag based on the taxonomy term (zone) and then use a css selector like

body.term-class li.active-trail

or

body.term-class a.active

where term-class is the class added to the body tag

nevries’s picture

No, I want to style the link on whatever page the user is. One could do something like this in template.php:

  • Grab the menu
  • Parse every link to get the node id
  • Load each node
  • Alter the menu items adding the taxonomy terms as css-classes of the appropriate nodes

BUT: This is

  1. a lot of error-prone work
  2. a very inefficient technique (load all nodes on every page request???)

Better would be to store these information on node save, but this is a module task, not a theme task, I think. And I'm afraid I'm not skilled enough to write such a module. So my question: Does anybody see a better/cleaner solution?