By yellowhousedesign on
Hi everyone,
Running into a bit of a snag with a particular need to add on a class to the body of a page that contains either the name, or just nodeID of the upper-most parent item in the menu. Basically, I need it to display a unique background image per "section" and its children. So, if you were on the Admissions page for example, you'd get a body class of something like "top-parent-node-33" and then for any pages listed under Admissions you'd also get "top-parent-node-33". I guess this could get a little funny with Views possibly, so the name... anything to identify it :)
Thanks for any help that can be given!
Comments
taxonomy and views!
You could do some custom coding within your theme templates. But then you have to go back on and custom code even more when your client wants to change those images.
Instead, use a custom content type for storing header images in fields, tag them with the matching section, and handle the output with contextual filters in the views module. Then when your client says next year that she wants different images or wants another section added then you can whip it up without sticking your head back in the custom code you wrote. All the work is done with core and a single contributed module.
There is almost nothing you can't do with taxonomy, fields and views.
Hey Sean, Thanks for the
Hey Sean,
Thanks for the insight on that - I definitely understand future implications for hardcoding anything like that into your template, but for this specific case, user editable fields were not necessary (as this is for a background image to a menu header -- based on the "hero parent" you are coming from). I was able to do some Googling and found this which suits my needs:
Obviously it'd be better if this was able to automatically grab the parent menu item, so if anyone wants to adapt this to do that or possibly find a way to add this to the template.php file that'd be great too ;)
Actually, This one seems to
Actually,
This one seems to be more "automatic":
Automatic parent menu item classes - full code
Hi,
as a kind of summery of the posts above:
To get a body class with the parent menu item name in D7 add the following function to your theme's template.php. (Change YOURTHEME with your theme name.)
Thats it.
Filburt
Slight improvement
Also, you can use the built in drupal function drupal_html_class() instead of your own regular expression:
Links with accents
Hy and thank you for what you've done for me all of you and particulary @drclaw :)
This work as well for me, i just search for something about how is the class rewrite, i have for example in my menu links with accents like 'ü' or 'é', it work allready but it will be cleaner for me to change that accents with no accent like 'u' or 'e'.
Do you think it's possible ?
Thank you
Transliteration
I believe what you're looking for is called "Transliteration" which can be achieved with the
transliterate_get()function.You could use context module.
You could use context module. It can write custom body class for menus you select.