Thursday, May 14, 2009

Create horizontal categories menu in WordPress without CSS

To create a horizontal categories menu separated by ' | ' in WordPress, use this code.
<?php
echo str_replace('<br />',' | ',
wp_list_categories('style=&echo=0&title_li='));
?>

5 comments :

  1. After two hours of searching on the web for a simple menu that does exactly what you've described...Thank you, thank you. I knew it had to be simple, and I don't need the CSS.

    ReplyDelete
  2. just another designeJanuary 16, 2011 at 8:31 PM

    Wow, excellent information! I cannot thank you enough for posting this. This gave me exactly what I needed, now if I could just figure out how to exclude the "Uncatagorized" catagory from showing in the menu. Anyone have any tips?

    ReplyDelete
  3. It is easy to exclude any category. Just add `exclude` to wp_list_categories(). For example, if you want to exclude category with id=2,

    <pre><code>wp_list_categories('style=&echo=0&title_li=&exclude=2');</code></pre>

    To find the category id,
    1. go to Posts > Categories.
    2. Hover to any category name, and look at your browser status bar. Look for something like `...&tag_ID=2...`. In this case, the category id is 2.

    ReplyDelete
  4. Thanks a million for this =)

    ReplyDelete
  5. I'd love to add some heirarchy to this script. any suggestions?

    ReplyDelete