An important factor in any good WordPress theme is navigation. Sidebar widgets can be used to add navigation to any blog, but sometimes a good navigation bar can be a much better choice.
Even if you're favorite theme has a navbar built in, it may not do exactly what you need it to. While a navbar may seem like a simple thing at first, there are actually a TON of different things that you can do to make sure your site is as user-friendly as possible.
[ advertisement ]
The first choice you need to make is how you want to use your navbar. Most of the time, navbars display either categories or pages. Some sites will display both, and can even combine the two into one line.. The only downside to the combined bar approach is that you can sometimes run out of space.
**Changing Your Navbar From Categories To Pages (or vice versa)**
If the navigation on your current theme isn’t displaying what you require, don’t worry! Switching from Category to Page based navigation is easy!
To do this, we'll be editing your theme's header.php file..
Your navigation bar is controlled by a template tag, either wp_list_pages or wp_list_categories.
Once you find your navbar's template tag in the header file, you can replace it if needed. More likely than not, there will already be some paramaters in the tag's parenthesis - we'll be adding to these later on.
**How To Locate The ID of the Page/Category You Want To Exclude**
Now that you’ve found the template tag that’s controlling your navigation, it’s time to add a parameter to disable the pages you don’t want to see. So, our next step is to grab the specific ID of the page or category we're focusing on.
When you create a page or catetory, you give at a name that you can identify it by. At the same time, WordPress gives it a unique ID number in the database. Finding that ID is easy. Just pull up the Page/Category list in WordPress and hover over the item you're working on - you'll see some links for that item appear.
Hover over that “edit” link and look at the bottom bar of your browser. The destination URL of the link is displayed, and ends with the page/category ID. For those of you on a Mac, you’ll just want to click the “Edit” link and look at the URL it takes you to.
At the end of the “Edit” URL, pages will say “post=” and categories will say “cat_id=” followed by a number. That number is the ID you need, and we’ll discuss where to use it a little later on.
**Excluding Certain Pages or Categories**
Removing an item from a navigation bar is probably the most popular modification people make on a WordPress blog. This could be a “Thank You” page for new subscribers, or an intermediate page for visitors going through a certain process.
Excluding a page from your navbar is easily accomplished by a parameter to your navigation tag. As you can probably guess, we're going to use what is called the "exclude" parameter.
To exclude the page you want, enter the parameter, followed by the ID of the page/category in question:
wp_list_pages('exclude=4,37,22')
This example uses list_pages, but list_categories works the exact same way. If you only have one ID, that's all you'll need to list. This example actually shows how to exclude multiple pages at once.
It is imperative that you remember the quotation marks and parenthesis as shown above.
**Choosing Particular Pages/Categories To Display**
On some sites, it might be easier to list the pages you WANT to see, rather than the pages you don't. The exclude parameter will work here, but if you have a big site, gathering ID's of all the other pages could take a while. The other drawback is you'd have to go into your header file and add the ID of any new page or category you add in the future
Yuck.
So instead of "exclude," we'll just turn to "include":
wp_list_pages('include=4,37,22')
Once again, this parameter works for both the page and category tags. Using include will display all the pages listed, so if you add new pages in the future, they won’t show up unless want them to (in which case, you’ll add the new ID to the template tag in header.php).
Note: Keep in mind that the order of the ID's here does NOT affect the order that your pages will be listed. To rearrange the page order, use the “Order” field, under “Attributes” in the right hand column of the the “Edit Page” screen.
**What To Do When Your Tage Has Several Parameters**
More often than not, there will be other parameters in your tag - in addition to the one you are adding today. The majority of themes will use the "title_li=" parameter to control the navigation list's title.
In general, a navigation bar doesn’t need a title, in this case, the parameter is left blank, with nothing after the equals sign. This is the equivalent of saying “don’t display any title.” Here’s an example of that parameter in action:
wp_list_pages('title_li=')
Okay, how do we get the existing parameter(s) to work with the new one? Like this!
wp_list_pages('title_li=&include=4,37,22')
Yup. It's that easy. :) Stick an "AND" symbol between each parameter and you're good to go. Note that the entire group of parameters (called a ’string’) is included within the quotation marks. Make sure those are in place, and that all of your parameters are inside them, and you’ll be good to go!
And that’s it! That is all you need to completely customize the display of your navigation bar.
Enjoy!
Author Resource:-
Chad is a self-proclaimed WordPress Junkie who works from home with his wife, Lynne.