Simple way to put categories in your navigation bar in wordpress

<  Simple way to put categories in your navigation bar in wordpress

Your navigation bar is typically included in the header.php file which is found in your theme folder. Browse down until you find a css mark whose id is “navigation”. In the aquafluid theme, this looks like this:

< ul id="navigation" >

Below this you have typically code that defines what goes in the navigation bar: for example the link to the home page and to other pages of your website. Simply add before the < /ul > code the following line:

< ? php wp_list_cats('sort_column=name&optioncount=0&hierarchical=0'); ? >

This will automatically add links to all of your categories in your Wordpress navigation bar, sorted by alphabetical order. If you want to show the number of posts by category, you should replace “optioncount=0″ by “optioncount=1″. Also, if you wish to exclude certain categories from your navigation bar, you can add the following after “hierarchical=0″ and before the ” ‘ ” sign: “&exclude=1, 2, 3, 4″. In this example, categories whose ids are 1, 2, 3 and 4 will be excluded. You can identify the numbers attached to your respective categories by choosing “manage –> categories” in the Wordpress admin zone.

A navigation bar that first displays a link to your home, followed by links to your categories but excluding categories 2, 3 and 5, would look like this:

< ul id="navigation" >
< li < ?php if(is_home()){echo 'class="current_page_item"';}? > >< a href="< ?php bloginfo('siteurl'); ? >" title="Home" >Home< /a >< /li >
< li >< ?php wp_list_cats('sort_column=name&optioncount=0&hierarchical=0&exclude=2, 3, 5'); ? >< /li >
< /ul >

Important note: do not copy the code lines above. To prevent the code from executing on this page we have added spaces after the “<" and before the ">“. You would need to delete these blanks to make the code functional.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • Technorati
  • LinkedIn
  • Slashdot

Related posts:

  1. Amateur webmaster tips: adding Wordpress tags to an old theme
  2. Amateur webmaster tip: importing Wordpress posts in another Wordpress blog
  3. RapidWeaver and Wordpress compared | Part II: the out-of-the-box experience
  4. Yet another way to simply put your latest Flickr pictures on your website
  5. Beginners’ wordpress tips: what are asides?

Posted in Web development, Wordpress ~ ~ You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Leave a Reply

Name (required)
Mail (will not be published) (required)
Website

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


«

 
Countries in Colors 2006-2008 Some rights reserved | Hosted by GoDaddy |
Powered by WordPress // Template by Mike Lothar // Updated by CiC