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 ChildTheme.
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!

By This entry was posted in Theme Design, Wordpress and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

14 Comments

  1. Him
    Posted March 21, 2009 at 11:00 pm | Permalink

    Thanks a ton Cristi!!!

    cheers

  2. Posted March 22, 2009 at 1:01 am | Permalink

    You welcome! :)

    • joojoo
      Posted July 19, 2009 at 4:18 pm | Permalink

      hi cristi thanx a lot
      but can u help me to place page menu just at start of page?

      • Posted July 20, 2009 at 10:58 am | Permalink

        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.

        • Mike Ciance
          Posted July 26, 2009 at 9:27 am | Permalink

          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');

  3. Posted August 7, 2009 at 9:09 pm | Permalink

    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.

    • Mike Ciance
      Posted August 8, 2009 at 3:56 am | Permalink

      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.

      • Posted August 8, 2009 at 10:45 am | Permalink

        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.

        • Mike Ciance
          Posted August 8, 2009 at 11:51 am | Permalink

          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.

  4. Posted November 5, 2009 at 3:21 am | Permalink

    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.

    • Posted November 5, 2009 at 7:35 am | Permalink

      Glad you found it useful!

      PS: The post about Thematic Theme Options Panel was really useful! ;)

  5. Leo
    Posted December 27, 2009 at 6:05 am | Permalink

    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.

  6. Posted February 13, 2010 at 11:47 am | Permalink

    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!

    • Posted February 15, 2010 at 11:16 am | Permalink

      Hi Kara,

      Could you post this on the cozmoslabs forums here: link.

      This way more people will benefit from the resolve!

One Trackback

  1. [...] e proviamolo. Articolo scritto da Cristi e pubblicato su CoszmosLabs. Tradotto con il consenso dell’ autore. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

* Copy this password

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>