Hello,
I am using Nice Menu's for my Primary Links and would like to append the menu item field 'description' to the Title that is hotlinked by the anchor tag.
I.e what I get now is:
<a href="http://www.mysite.com>My Title</a>
and I would like this:
<a href="http://www.mysite.com>My Title<br />My Menu Description</a>
.. or this!
<a href="http://www.mysite.com>My Title</a>My Menu Description with html
I am overriding mytheme_menu_item_link in my template.php and thought something like this would work:
function northstudio_menu_item_link($item, $link_item) {
$title = $item['title'] . '<br />' . $item['description'];
return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL, NULL, FALSE, TRUE);.. but it doesn't ..
Also, I need to figure out how to just make this change on my Primary Links only and leave the rest of the links on the site alone. I would imagine all links are built using menu_item_link.
Any help would be greatly appreciated!
Dave
Comments
Nice Menus - Adding menu description to the link
Hello?
hmmm
You know .. I'm thinking this can't really be that hard. In fact I really don't understand why the code above doesn't work. Someone familiar with menu_item_link would surely know though! ...
Anyone familiar
Anyone familiar with menu_item_link?
Still trying ...
.. to solve this one.
Nice Menus - Adding menu description to the link - menu_item_lin
I am taking a different route here. Since overriding and editing menu_item_link() with built-in logic to only alter one of my menu's link structure is obviously over my head ... I have resorted to bad practice .. I now editing my nice_menus.module!! hack!
Ok, I also decided I wanted some additional functionality as well so I had to! I still need some help though as I explain below.
Here is what I am doing though ...
1
I added this extra code to line 17 above which creates a second anchor element (a tag) just prior to the a tag created by menu item link.
'<a class="menuiconanchor" id="menuicon-'. $mid . '" href="#"></a>' .This way I have two anchor tags in my menu item. With a little css styling I have have them side by side. I plan on adding a background image to my new anchor tag so I can add nifty little icons to my menu on the left of the actual menu link. Right now as you can see I have only added it to menu items that have children (menuparent's), but will add it below the 'else' as well so all menu items can have the second tag.
I DO HOWEVER .. still need a bit of help if anyone is out there. I want to add yet a third anchor tag to my menu 'after' menu_item_link and I want to populate it with the text from the menu description field. I also want the ability to add html in the description field and have it carried through to the anchor tag .. which I think it should do all on it's own.
I will format the 3rd tag with some css as well and I suppose add a line-break before the description text so my description shows up on the second line of my menu item.
So .. If you can help me out just a tiny bit to grab that menu description text I would most certainly appreciate it.
Dave
Solved - Adding Icons & Descriptions to Nice Menu's
Here is how I did it.
http://drupal.org/node/468664
This is now a handbook item for Nice Menu's
http://drupal.org/node/470558
Will this work in Drupal 6
Will this work in Drupal 6 too? is the code much different?
Becky
Code will be different
This will not work directly for Drupal 6.
1) The Nice Menu's function theme_nice_menu_tree looks like it is changed to theme_nice_menu_build, although you can find the output strings being built on lines 322 and 332.
So under D6, Nice Menus is slightly different and it looks like accessing a menu item has changed as evidenced my $mlid instead of $mid for the menu ID, but you can surely add your extra classes in there to display an icon or other content.
If you also want to put additional HTML text in your menu from the menu's description I can't really help you there because I do not know how much the structure changed for the menu item array. If you see above I used a very simple custom function in my template.php to extract the text from the menu description field. This function would have to be altered to get the description text out of the D6 menu item array properly if it has changed.
But other than that, it would be pretty simple and straightforward.
Thanks for the feed back. I
Thanks for the feed back. I have a couple of follow up questions. I'm really new at drupal programing.
1. how do i find out what the menu item array is? Do you mean a menu item array for nice menus or is this a standard drupal menu array?
2. what does $mlid mean?
3. Where would I go to learn about how I should properly alter your original function to meet D6 standards?
Thanks,
Becky
Ok I started editing the out
Ok I started editing the out put lines, just using your example classes from your handbook page. I made sure that all the $mids became $mlid though. This is what I have. It does not work. I probably have a syntax error but I am not good enough at php to figure out what it is. Could someone lend an eye to this?
Comments
I looked at your first 'output' string and it all looks correct to me. Perhaps the place to start is to ask ...what exactly does not work? It it throwing some type of error?
My guess is that you didn't deal with the custom function that gets the menu description text. As stated earlier I put a simple custom function in my template.php file called c_menu_item_description which accepts the menu ID and return the menu description text.
The problem you are going to have is that my custom function as shown above uses get_menu_item($mid) as follow:
In looking at the Drupal API (found here: http://api.drupal.org/api/function/menu_get_item/6) you can see that get_menu_item has changed from version 5 to version 6.
So you have two options as follows:
1) You can remove the call to c_menu_item_description() which means everything else will work but you wont have the menu description text available.
2) You can edit the c_menu_item_description function I have provided (which you need to put in your template.php) so that it correctly calls the version 6 menu_get_item() and properly returns the description text.
Also, as a matter of debugging, try changing only one of the output string (say the parentmenu one) and leaving the other original. Remove the call to the custom function for the description text and see what happens. It should work. You can tell if it works by using Firebug and seeing if your new div containers and classes show up in any of your parent menu items.
Then once that works, add the second output string without the description text function. Get that to work.
Then after you feel comfortable that your divs are getting inserted the way you want, then try to hammer out how to get the description text.
That's what I recommend anyways.
Dave
Ok. Thanks for your feed
Ok. Thanks for your feed back. Your guidance is very much appreciated. I will report back after I have followed the options above. I think i will have to re write the function too..That might take time. I have never written a function before.
Becky
Could I use this to make the
Could I use this to make the function: http://api.drupal.org/api/function/menu_link_load/6 It seems use mild. What do you think. I can't make heads or tails of the menu_get_item...
Becky
Shorter Approach to Menu Descriptions
This method seemed a little long winded to me for the description text, so I did a direct call from the array in the output, seems to work alright;
This is near the end of theme_nice_menu_build. Stuff I added is bordered with the NEW comments.
Wow, this is great. Thank
Wow, this is great. Thank you for taking the time to look at this. With this, do i still need a template function?
Thanks! I will try this out asap.
Becky
template.php
can this be included in template.php so no hack of nice menus is needed?
Thanks this worked great!
Thanks this worked great!
mediamash: Yes, I copied the theme_nice_menu_build function and pasted it into my theme's template.php (renamed to mytheme_nice_menu_build).
What are the chances of this
What are the chances of this getting updated for Drupal 7? I've been trying to do this for days but can't find any help for D7.
Thanks!
Really nice, Nice Menus - Share your sites please.
Would love to see some of the custom menu's people have created using this technique. Thanks for sharing. -Dave (www.3xlogic.com)