With the launch of Thematic 0.9 we now have out of the box drop-down menus to work with. This is one of the many features added to 0.9 that was requested by the community. However sometimes one might want to replace the default Thematic menu with a menu composed with the categories and sub-categories of your WordPress installation.
Although I’ve done in the past a similar tutorial that one isn’t working anymore with the latest Thematic version so here is a quick and easy way to add a Category DropDown.
First create a Child Theme.
Second create and then open the functions.php file that should be found in your new ChildTheme.
Third add this code to the functions.php file:
[sourcecode language=”php”]
#Add a drop down category menu
function childtheme_category_menu() { ?>
<div id=”category-menu” class=”menu”>
<ul id=”category-nav” class=”sf-menu”>
<?php wp_list_categories(‘title_li=’); ?>
</ul>
</div>
<?php }
add_action(‘wp_page_menu’,’childtheme_category_menu’);
[/sourcecode]
Save and test. You should now have a drop-down from your categories!
Related Articles
15+ Best WordPress Membership Themes in 2024
Looking for the best WordPress membership theme? We collected 20+ free and premium options, all of which make a great option for membership websites.
Continue ReadingBeginner’s Guide to: What Is WordPress?
Ever now and again the question arises with new clients that aren't really tech savvy: "What Is WordPress?" What I'm hoping to achieve with this post is to drop the technical jargon for a minute and explain in down to earth words what is WordPress, how can it help you, what is WordPress.com, what's a […]
Continue ReadingThe wp_nav_menu Shortcode for WordPress Menus
Since Wordpress 3.0 we have access to the really useful wp_nav_menu shortcode functionality. We can now create our own menus without resorting to several plugins or tricks. Another cool thing we can do with this new menu is build the sitemap. I was in need, the other day, of a plugin that would generate a […]
Continue Reading
Thanks a ton Cristi!!!
cheers
You welcome! 🙂
hi cristi thanx a lot
but can u help me to place page menu just at start of page?
Replace
add_action(‘wp_page_menu’,’childtheme_category_menu’);
with
add_action(‘thematic_aboveheader’,’childtheme_category_menu’);
That should put the menu on top of your theme. Note you’ll still have the default menu available.
Perhaps more useful, a function to put the categories right under the regular menu.
Replace the line with:
add_action('thematic_belowheader','childtheme_category_menu');
[…] e proviamolo. Articolo scritto da Cristi e pubblicato su CoszmosLabs. Tradotto con il consenso dell’ autore. […]
Great…
Do I need some additional/extra CSS-ing to make sure it is displayed vertically/dropdown?
‘Cause now I’m getting the categories just show horizontally…
Thanks in advance…
Regards.
You need to make sure that you have subcategories defined, and that those subcategories have actual articles in them. This code only displays used categories, so if you just added a new subcategory it won’t show up in the dropdown until you associate an article with it.
Thanks for the reply, Mike.
But I think I was expecting something more/else…
What I want is a label ‘Categories’ and right beneath that the dropdownbox with categories.
I can simulate this my creating a ‘dummy’ category called ‘Categories’ and make that the parent of all the other categories…
I’m wondering whether this is possible without a dummy category.
I’m not a PHP whiz, but I do know a lot about CSS. If you create a parent list for the list that the PHP generates, and then you apply the proper CSS styling to it as shown here http://htmldog.com/articles/suckerfish/dropdowns/ you should be able to get that to work, albeit without the flashy javascript animation and without support for IE6.
I’m sure there is a better way, but that’s one possibility.
I needed to generate a category dropdown after the page list, and ended up posting a few different ways to do this through Thematic hooks and WordPress filters on my site: http://wordpresstheming.com/2009/11/filter-menus-in-thematic/.
Your post definitely got me started in the right direction.
Glad you found it useful!
PS: The post about Thematic Theme Options Panel was really useful! 😉
dumb question…how do we do the same thing for the page list (top menu?). i’d like to do the same as on your commune theme.
I know this is an old thread, but in the hopes that someone still reads it… 🙂 can you tell me how I would exclude the “Uncategorized” tag from showing up on the menu? I tried just adding excluded=1 right in the below code before the title_li… but that just makes the formatting funky, and it adds uncategorized as a sub menu. help! I’m a total newbie to php and css and all this fun stuff!
Hi Kara,
Could you post this on the cozmoslabs forums here: link.
This way more people will benefit from the resolve!