By nimzie on
Hi,
For my main nav, I have buttons designed with IDs. There's an Active type as well. What I need to do is create the menu in Drupal, assign an ID to each menu item and be able to configure my "active" css state, too. Not so sure how to go about this.
Thanks for any advice.
Cheers
Adam
Comments
Sorry to re-post in my own
Sorry to re-post in my own article. What I'm looking to do is have a menu I can make in Drupal. That menu has 5 items. Each has its own ID. Also, when one is clicked, it would have an Active state which I can tie to my CSS as well.
Is there a component or some snippets of code out there which can help me do this?
Thanks,
Adam
I'"ve figured out part of
I'"ve figured out part of the problem. I've entered this function in my template.php
and this code in a menu_item.tpl.php file:
This works perfectly when I click on one of my top menu items images. The active class is implemented as desired.
I would like to make these menu items "category" or taxonomy aware so when I'm on a page of X category, that category's corresponding top menu item is "active". As it is, when using the top menu only, the proper menu item stays "active" but as soon as I navigate other site items (which are categorized corresponding with the menu), the active state is not used.
Please advise.
Cheers,
Adam
Could what you describe also
Could what you describe also be used to highlight one menu item?
This need not be the active one? Just to give this menu item more look-and-feel?
greetings,
Martijn
Solution for Drupal 6
Hi!
Unfortunately this doesn't work in Drupal 6 since _phptemplate_callback() has been dropped. However in Drupal 6 it's really easy to achieve the same thing, just put this in your template.php:
What I'd really like to achieve though would be having the list items numbered, this I've also tried to achieve in other occasions. It'd be really nice to be able to obtain the iteration number ($i) of the loop repeatedly calling this function. A dirty solution would be to use global variables and add one each time that the function is called, but I know that's not the way to go. Please Drupal gurus, enlighten me on this. ;) (I wanted to achieve this also for gallery index pages, in order to be able to position the items. So this piece of knowledge would be useful for many purposes.)
cheers, Simon
So .. back to this one...
OK - I've managed to get a better understanding of Drupal. Simply using a menu as Primary and another as secondary maintains the active link between subnav and top nav.
My issue: for each section (think top nav) of my site, I slide in a different subnav menu. I'm not sure how to get things to stay "active" in the primary nav when I am navigating through secondary nav items.
i.e. If I'm in the "people" section of my site - I show the people menu as subnav. Clicking on a person in the subnav should maintain the active state of the "people" nav item up top.
How do I maintain this when I'm using different blocks for different menus?
Me too.
I'm trying to do the exact same thing. I am using blocks as a 3rd level subnavs. When you click on a third level link, the 2nd level of navigation disappears.
Did you ever figure out how keep the state on the 2nd level menus, nimzie? I'll let you know if I do!
I worked with coreyp_1
I worked with coreyp_1 (thank you - you're a Drupal Deity) to come up with this solution.
For my main nav, I'm outputting this.
For the secondary nav, I've created a block with the following code. This block IS my subnav code:
I've got a new module which Corey developed for me. You can download it at:
http://shorelineconsulting.ca/upload/custom_menus.zip
Install it as a module and your block code will just "work".
To see this menu in action:
http://brighthost.ca/nsfa_main/
Drupal 6?
It looks like this is for 5.x. I've started to convert it for Drupal 6.x but am having a hell of a time so far. (This is my first attempt to update a module.)
I can't help but wonder... Is there an easier way to do this in 6 with the revamped menu system?
I worked with coreyp_1
I worked with coreyp_1 (thank you - you're a Drupal Deity) to come up with this solution.
For my main nav, I'm outputting this.
For the secondary nav, I've created a block with the following code. This block IS my subnav code:
I've got a new module which Corey developed for me. You can download it at:
http://shorelineconsulting.ca/upload/custom_menus.zip
Install it as a module and your block code will just "work".
To see this menu in action:
http://brighthost.ca/nsfa_main/
I tried to figure that out
I tried to figure that out for hours! Thanks a lot!!! Works perfect! No I can begin to set up my CSS!!
Drupal 6
Ronnqvist
Does this solution work for custom menus (not using primary/secondary menus) in Drupal 6. I need to have the menu image highlighted for the current page. If this soultion provides me with the unique id/class for the page, then I can use it to style the menu image for each page.
regards
Shrenster
A better solution imho for Drupal 5
this doesn't require an additionnal menu-item.tpl.php and it creates nicer classes
In template.php :
Also for drupal 6
An alternative of the code posted above, using id-safe of zen to turn every item to lower case, and only use class, because id is not safe markup. If two menu items have the same name, it would give two similar ids :
In template.php (without the php opening and closing) :
This is exactly what I'm
This is exactly what I'm looking for as well. However, it seems that my template.php file is totally ignored. I'm trying to do this with my primary menu items. Does that require a different function?
If Drupal 6
If you are in drupal 6, you need to refresh the theme cache when you change the template.php. You can do this by just visiting the theme page. and validate without changing anything.
______________________________
www.couzinhub.com
You are right!
You are right!
I was under the impression that I had already done this, but that nothing had changed. Thanks a lot!
If you want to avoid having
If you want to avoid having to do that every time you change the template.php, you can either use the devel module, I think there is a function that clears the cache on demand. Also, by using the ZEN theme, you can activate 'clear cache on each page reload'. It's just a bit demanding on memory so make sure you turn it off after development. Basic 2.1 (not released yet) also have that function.
You can also visit the page admin/settings/performance. A button clears the cache.
______________________________
www.couzinhub.com
Wow -- deep gratitude
This is most excellent -- AND standards compliant. Look away from using id's, all.
This is a great addition,
This is a great addition, thanks! I'm still baffled that it's not included in the Drupal core menu creation process...
Have I helped you? Consider buying me a beer.
You can find this code in
You can find this code in some base theme, I included an improved version of it in Basic
Just what I was looking for
Subscribing... This is exactly what I was looking for. It does just what I wanted in D6.
Thanks,
Andrew
now with 'parents'
I've combined the code above with another snippet I found so that now the snippet adds an active class to li elements and a elements, custom id to menu items links PLUS - a 'parent' class to menu items further up the food chain. I didn't write any of it, just shuffled it around a bit.
[[[ ALL HAIL THE ALMIGHTY GOOGLEBOT ]]]
This doesn;t work for D6
This doesn;t work for D6 anymore..menu_in_active_trail($mid) is not in API, right? Anyone has other suggestion for D6 please?
Thanks a lot in advance for your reply!
greetings, Martijn
Not Woking as desired
this does add the ID to each of the links but some how the LI's become double space.
I can not figure out why.
There does seem to be some odd character in front of the
subscribing
subscribing
Menu Attributes and Menu Class
Have a look at this:
Menu Attributes
http://drupal.org/project/menu_attributes
Menu Class
http://drupal.org/project/menuclass
Slightly adjusted for D6
I've just slightly adjusted couzinhub's code Here to make it a little more compact and I'm using a core D6 function to sanitize the class before attaching it to the link. Add it to template.php in your theme and rename the function to match the name of your theme.
Now... what do we do about D7 ?
Like the original commenter said over two years ago, I cannot believe this type of functionality is not part of core. I only wish I had the PHP chops to be able to write this and advocate for it's inclusion. The fact menus don't have as a default, specific class names and or ID's associated, along with active states seems to me like a bug. That aside, I wonder if anyone has tackled this for D7 and would be willing to share a snippet. I see the Basic theme has been updated to D7 so perhaps the requisite code is within.
Kind regards,
Andrew
Edit: I found something that works, at least on my subtheme of Adaptive Theme. Place the following code in your preprocess section of your themename and you manipulate the defined menu. Perhaps this can be extended by someone more knowledgable than me.
Compacto!
Since we're compacting I thought I'd take it one step further and use the core theme_menu_link function to do most of the work: