How to exclude pages/categories from navigation listings on WordPress « Kevin Pajak – Interactive Web Developer/Designer – BLOG

How to exclude pages/categories from navigation listings on WordPress

November 10th, 2009

OK, I am writing this post to share a little bit of info that I discovered last night, while doing some WordPress editing work for a client of mine. He had several categories and pages that needed to be included on his site, but he wanted five pages to be linked in the footer that obviously we didn’t want to re-list in the main nav listing that appeared in the theme’s Header. After doing a bit of searching online, I did discover this post in the WP dev forums:

http://codex.wordpress.org/Template_Tags/wp_list_pages#Exclude_Pages_from_List

This covers the basics of how to exclude pages from your navbar listings, but there’s only one problem (and at first I was freaking out over this): they indicate to exclude by page ID, but the newer versions of WordPress don’t use a page ID, SO, here is what you do:

1) Go to ‘Pages > Edit’
2) Mouseover the page you will be wanting to exclude from your list, and see the URL that appears (for example: http://www.kevinpajak.com/blog/wp-admin/page.php?action=edit&post=2). You notice that you will actually see the number listed as a post!
3) Grab this number for each page you need to exclude, and plop it into this code in your header/sidebar/navbar page code:

For example:
<?php wp_list_pages(‘exclude=16,18,20,22′); ?>

Voila! You should be all set (Oh, and if your wp_list_pages function happens to have additional code, you will need to make sure you include the ampersand character with it (&).

Ex:
<?php wp_list_pages(‘title_li=&exclude=96,98,100,102,104′); ?>

Last of all, there is also a plugin you might want to try, called ‘Exclude Pages’ that should take care of this for you automatically if you prefer. I haven’t tried it yet, but definitely worth a look ;) .

Have fun WordPressers, good luck, and please feel free to share your feedback anytime! :-) .

————————————————————-

PS: To exclude categories from your navigation listings, follow the same procedure:

1) Take a look at your overall category list (‘Edit > Categories’),
2) This time find the CAT ID (Ex: http://www.kevinpajak.com/blog/wp-admin/categories.php?action=edit&cat_ID=3)
3) Note that number(s) and enter them in the line of code that reads, for example:
<?php wp_list_categories(‘exclude=6,8,21′); ?>

Tags:

Leave a Reply