Hi,
I'm currently trying to theme Drupal, and am implementing a main site nav as a menu. The site nav uses CSS tabs that require the LI of an active tab to hold the 'class="active"' portion of code rather than the A tag as is usual with Drupal.
Is there anyway to achieve this? I've search drupal.org and there doesn't seem to be any fixes or mods that will do quite what I want. I've also ducked around the source code, but I can't find where the relevant piece of code despite doing a search on the drupal folder.
Any help would be overwhelmingly appreciated :-)
Also, would it make more sense in some ways to have the LI carry the class="active" declaration as standard, as then a CSS rule can easily cascade down the hierarchy:
i.e.
LI.active A { styles..... }
as well as allowing
LI.active
Comments
bump
:)
last chance!
is there really no way to alter this?
Partial Solution
After much reading and messing around with templates and php, I've found a way of achieving this for the home page.
This requires the patch to allow an active class to be added to the home link on the home page (see here: http://drupal.org/node/45098)
You can then use str_replace in the home page template to alter the location of the class="active" string.
I'm not sure I like it messing with the href in the link though, and because it does this its not going to work with the templates which power more than one page.
Possibly something using regular expressions would fix this for other templates.
Full Solution
Ok, I figured it out :)
You need to use this code on page.tpl.php in your theme instead of the standard call to display the $header:
I still think that making a change to Drupal to permanently shift the 'class="active"' to the LI tag is more useful for CSS coders and a minimal change. I'd imagine it would require many themes to be updated however.
I found a somewhat fix in
I found a somewhat fix in teh menu.inc file
I changed the function theme_menu_item() from
to:
Seems like quite the hunt just to find out how to change one little class...I don't think the core programmers have ever heard of the MVC method of development, would have really helped to not have output/logic/database code all mashed together into one ball of fun!
Hopefully that helps out a bit.
in 5.x
I made great use of this trick in 4.7--but I can't figure out how to implement it in 5.1. Has anyone done it?
This worked for me
I was able to accomplish this in 5.1 with the following code:
Place this in template.php. Replace "theme" in the function name with the name of your theme.
Jeff Tomlinson
thanks!
It works!
Didn't work for me in Drupal 5.11
for some reason.
But if anyone else is having troubles with the above mehtod and wants to do this I did it with jquery instead:
Øyvind Strømsvik
oyvind@nymedia.no
Ny Media AS - www.nymedia.no
Øyvind Strømsvik
Tech lead | Frontkom AS
https://frontkom.com/
It works fine with 5.14
Remember to change "theme_menu_item" into "yourtheme_menu_item".