Exclude Certain Categories

For many bloggers, good navigation is one of the most important parts or a good theme. Sidebar widgets can be used to add navigation to any blog, but sometimes a good navbar can be a much better choice.

For many bloggers, good navigation is one of the most important parts or a good theme. Sidebar widgets can be used to add navigation to any blog, but sometimes a good navbar can be a much better choice.

Unfortunately, not all themes are designed with a navbar, and even those that do won’t always fit your individual needs. You’d probably be shocked by how much you can actually do with a WordPress navbar.

The first thing you need to decide is what you want your navbar to display. Normally, navigation bars come in two types: Categories and Pages. Some blogs (like this one) will use two navigation bars, one for each option – or even combine the two into one line. The one line approach may or may not work for you, depending on how intricate your site is.

**Changing Your Navigation Bar From Pages To Categories (or vice versa)**

There’s an easy way that you can change what your navigation bar shows if it doesn’t presently do what you need it to.

To do this, we’ll be editing your theme’s header.php file..

Your navbar is controlled by one of two tags, either wp_list_pages or wp_list_categories.

Search your header.php for the tag that applies to you, and if you need to, you can replace it with the one you’d rather be using. More likely than not, there will already be some paramaters in the tag’s parenthesis – we’ll be adding to these later on.

**Locating 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. In order to do this, you’ll need each of those pages’ ID numbers.

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. To find that number, pull up the page (or category) editing screen of your dashboard. As you hover over each entry, a row of links will appear, one of them being “edit.”

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.

 

**How To Remove Specific Pages or Categories**

Removing an item from a navbar is probably the most frequent modification people make on a WordPress blog. Sometimes this is done to hide a “Thank You” or Privacy Policy page.

Excluding a page from your navbar is easily accomplished by a parameter to your navigation tag. This is the (you guessed it!) “exclude” parameter.

To exclude the page you want, enter the parameter, followed by the ID of the page/category in question:

 

You can use this exact same parameter with the list_categories tag. 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.

Make sure you include the quotes and parenthesis as shown, or the tag won’t work right!

**Only Including Certain Pages/Categories**

If you have a situation where you only want to list specific pages or categories on your navbar. The exclude parameter will work here, but if you have a big site, gathering ID’s of all the other pages could become pretty boring. Plus, you’d have to constantly update the code whenever you added something!

No one want’s to do that.

Don’t worry though! There’s always the “include” parameter:

Just like the “exclude” we used earlier, “include” can be applied to both the page and category based navigation tags.

Note: Changing the order of the ID’s in this tag will not change the order that they display on your site. Rearranging the order of the pages can only be done on the “Edit Page” screen, in the “Attributes” section

**Adding More Than One Parameters**

As I mentioned above, the template tag you are modifying probably already has some parameters already defined. This usually includes “title_li=” – which controls the title at the beginning of the list of pages/categories.

Commonly, a navbar doesn’t need a title, and the parameter is left blank – exactly as it is shown in below. This is the equivalent of saying “don’t display any title.” Here’s an example of that parameter in action:

 

Now the obvious question is how you add your new parameter into the mix? Like this!

That’s it!:) Stick an “AND” symbol between each parameter and you’re done. Note that the entire group of parameters (called a ‘string’) is included within the quotation marks. If those aren’t set up properly (see above), you’ll run into trouble!!

And that’s it! That is all you need to completely customize the display of your navigation bar.

Enjoy!

Picture of Brandon-P

Brandon-P

Leave a Replay

About Us

At WP Website Lab our goal is not to sell you a website but rather serve you with the entire web experience so that you see a return that’s is worth your investment.

Recent Posts

Follow Us

Weekly Tutorial

Sign up for our Newsletter