By mruzekw on
I was wondering if there is an override or a module out there that would allow me to set a custom CSS id for a menu item.
It would help me greatly so I can style each menu item separately.
I was wondering if there is an override or a module out there that would allow me to set a custom CSS id for a menu item.
It would help me greatly so I can style each menu item separately.
Comments
What I did
Hello,
You may try creating your own function and then using that one for the links that you want to modify.
I created a custom function to handle JUST my primaries and that works well for me.
I called mine theme_name_custom_primaries() -- Note that this function does not end in (links), this is for a reason. Using the theme override (as in - theme_name_links()) to manipulate just one set of links is a bad practice as it can quickly get out of hand if you need different changes for different menus.
Regards, Derek
http://collectivecolors.com
Hello, Could you give a
Hello,
Could you give a concrete example what you mean? I learn by example, and I'm a complete novice compared to others.
Thanks,
Will (linuxlover101)
This is the function that I
This is the function that I use to render my primaries at the (NEW) CollectiveColors site (You cant see it yet - still in the works)
You may notice that it is simply just a hacked up version of the regular theme_links function. I used this to number the links classes and, subsequently, modify the first (Home links)...
Here is what it looks like in use (page.tpt.php)
Hope that helps. I am not saying what I did was "right" though. But it does work, and it leaves all the other links alone.
Regards, Derek
http://collectivecolors.com
No need to store in db you can store id in varibale_set() method
Hi linuxlover,
I want to suggest you to store the menu id in the varibale_set('_', ''); and get the varibale according the menuid. I think it will solve your problem easily.
OR
one hard way is to create one another table table and write the trigger when insertion goto menu_links store the menuid and your css id into the table. Same thing for update and delete the menu item.
And get the css id from custom table by querying into our custom table.
Hope this will help you. Or you have better solution than this plz let me know.
Thanks,
Mrugesh Panchal
Hello, Your second option
Hello,
Your second option seems very complicated, so I'd like to focus on the first one.
I'm fairly new to Drupal and consider myself a novice compared to others. Could you give an example of a variable set for my situation?
Thanks,
Will (linuxlover101)
Apply custom class for menu item
Please call this function in your main page.tpl.php file.
Please read and every line carefully. Might be it would be helpful to you.???
Thank you,
Mrugesh Panchal
I did some more research and
I did some more research and looked through the API and found the theme_menu_item function.
I'm thinking more along the lines of this snippet of code (stolen from http://drupal.org/node/67457#comment-864218):
With this snippet I can just use the link name as the id, which is adequate if the site I'm building has static primary links.
When I place the snippet in my template.php file, clear the cache, and load the page: nothing changes.
I then used the devel module to show me what function was rendering the primary links (what I mainly want to style). It said theme_links() rather than theme_menu_item() was rendering the menu. Could this be an explanation why something didn't happen? Should I override the theme_links() instead?
Thanks,
Will
I went ahead and tried an
I went ahead and tried an override for theme_links() and it worked.
Here is the code:
Any ideas why theme_menu_item() didn't work?
Is there a way I could just focus on the primary links instead of all of the links on the page?
Any simpler fixes?
Thanks,
Will
That's why I was saying to
That's why I was saying to make a special function to deal with only those menus that you wanted to manipulate. Then you call that function instead of the regular theme links.
Having a series of cases to deal with each of your menus is not a good practice as it can rapidly escalate into incomprehensible garbage code... It looks like what you have should not have too much adverse impact though so good work. That will, as you noted, apply to (almost) all links but if it doesn't get in your way I see no reason why what you have would not be a decent solution.
Derek
http://collectivecolors.com
Thank you very much for your
Thank you very much for your help; I have implemented a solution that seems to be working fine. I'll make sure to refer back to this if I need to change anything.
Or you could use a module
http://drupal.org/project/menu_attributes
It works great!