By pommac on
Hi!
The site I'm developing has a couple of menus, styled differently from each other. The top nav HTML I'm working from looks like this:
<ul id="mainnav">
<li><a href="#" class="selected">Om Myndigheten</a></li>
<li><a href="#">Resurser & Material</a></li>
<li><a href="#">Projekt</a></li>
<li><a href="#">Aktuellt</a></li>
</ul>
<ul id="teach_press">
<li><a href="#">För Lärare</a></li>
<li><a href="#">För Press</a></li>
</ul>
So I need to put a different id on every menu. Is there a clever way to do this without hacking the core?
Comments
Template.php looks like a good start
I poked around a bit and modified template.php to include this function:
So at least now I know how to override the ul! The question is, what value can I use as id? I have full access to the css, so as long as it's something unique that stays constant it'll work for me. Any ideas?
One solution
Well, I'm coming a little closer and this is the best I've come up with so far:
Thus I get id's looking like "menu-65" etc and I can use that. But I don't think the pid is constant, is it? It won't be 65 when I've moved my theme to the production server and my client adds the "real" menu, will it? One way to fix that might be to grab the name of the menu and shake it up a little. For instance, one of the menus is called "Main Navigation": I could use a lowercase variant of that without spaces, grabbing the first 8 characters or so. It would become "mainnav" and that's both usable and portable.
So how can I extract the name of the menu being rendered? Anyone know?
Solved it!
Well, I keep replying to my own comments, but hopefully someone might find this useful in the future :)
This function in template.php will return an easy-to-use id for the css!
Thank you for posting this solution!
Can't thank you enough for taking the time to come back and post this! Have been looking for this solution for about a week now. Peace
Jeffrey Dalton
Creative Director & Founding Partner
BKJ Digital
https://bkjdigital.com
Thanks!
You sir, are magnificent. Just happened across this looking for a solution to something else, worked like a charm. Go pommac!
[[[ ALL HAIL THE ALMIGHTY GOOGLEBOT ]]]
This is great, however I
This is great, however I think for anyone trying to use this may run into issues with things already being declared.
My site was already using another phptemplate_menu_tree snippet, so this one wouldn't work for me right away.
(Tried merging the two snippets but they didn't play well)
By changing the first line ->
from this:
function phptemplate_menu_tree($pid = 1)to this:
function theme-name-goes-here_menu_tree($pid = 1)-should help you out in a tricky situation.
You can use firebug to see implementation at:
-- http://www.simplespot.ca --
Does this solution work in
Does this solution work in Drupal 6? I tried this piece of code and there was no output. Maybe it is a problem with $pid because I checked that this new function works but the if condition is not [I tried to echo some output and it didn't show and above the if there is the output]. Maybe someone could help me to adjust this function to D6?
Cheers
Invi
Refer this link on how to
Refer this link on how to override drupal 6 menus for theming. Here, you get an idea on how to override menu_tree, menu items and menu links.