I want to add category 'descriptions' to my main navigation (list categories) for a theme I am working on.
I am building this theme on WordPress 3.0, and would like to utilize the wp_nav_menu functionality, but cant seem to get it to display the category description as well.
The end goal is to do something like this - http://www.woothemes.com/demo/papercut/
Using the new menu navigation tool in wp 3 and have it display my categories, but also have it display each category description. I already have everything worked out except getting it to display the category descriptions.
Here is my current html structure for this area:
[[LINK href="http://pastie.org/993046"]]View Code[[/LINK]]
Utkarsh Kukreti answers:
I was going to publish a similar tutorial in my site in a few days. Here's the modified code of it, to insert description inside em
add_filter('walker_nav_menu_start_el', 'description_in_nav_el', 10, 4);
function description_in_nav_el($item_output, $item, $depth, $args)
{
return preg_replace('/(<a .*?>)/', '$1' . "<em>{$item->post_content}</em>", $item_output);
}
Will produce
<a href="#"><em>The Description</em>A Category</a>
Aaron comments:
For me this did not wrap the description in em tags. Also can it flip-flop the category name and the description, so that the category name comes first, and then the category description with the category description wrapped in em tags?
Thanks
Utkarsh Kukreti comments:
Try http://pastebin.com/LKtDP63h
Aaron comments:
Looks good, except it does not close out the a link tag. it outputs this to the screen /a>
It's missing the '<' before the closing a link tag
Utkarsh Kukreti comments:
http://pastebin.com/NVcUsTY0
Oleg Butuzov answers:
can i help you? you want to show the category description? or you want to show the description of the nav_menu witch is relates to the category?
Aaron comments:
Yes to display the category descriptions.
Oleg Butuzov comments:
that's no sence. in this case you will need to amke twice more db queries for each of the menu items.you can duplicate the the category description inside to the navigation menu. if thats ok for you i can make a custom filter for your menu.