Exclude Pages in WordPress list pages

Posted By Keith Dsouza On October 2, 2007 @ 6:19 am In How To,WordPress Tips and Tricks | 7 Comments

I recently implemented a Google Custom search on this blog by following some good advice from Maki on how to set up Google custom search [1]. The steps included creating a new page and adding the Google Custom search code to it, all went fine with the setup, but I came across a problem where I did not want the page to show up in the menu that is there at the top of this page.

The reason was that the title was too long and it was breaking the page and that I did not want it to be a part of the main menu.

Below is a screen shot of how the page was breaking the entire menu. If you see the page title was not aligning properly with the menu.

techie-buzz-menu [2] 

Now I did not want the page to appear this way so I found out a way I could exclude this page from showing up in the menu list. It is quite simple and requires you to modify your theme a bit. Let’s look at how exactly this can be done.

WordPress Code

wp_list_pages is a WordPress method that allows you to list the pages that are available on your blog, you can add this code to your theme wherever you want the list of pages to appear. In case of this blog I am using the list pages as a navigation menu.

wp_list_pages function accepts different parameters and one of them is the pages that you want to exclude from appearing in the list.

Lets see how you can exclude certain pages by following the simple instructions given below.

Get the page id(s)

You will require the page ids in order to exclude them from showing up in the list. For this you will have to login to your admin panel and go to Manage -> Pages. The id of the page will be displayed along with the page names, you have to make note off this id, or multiple ids for the pages you want to exclude from showing up.

manage-page-with-ids [3]

Changing the theme code

Once you have the id, open the theme editor and edit the file where you have used the wp_list_pages code. You need to add a parameter named exclude to the existing parameters used for the method.

Below is the modified code for this blog using which I excluded the page from showing up in the list;

<?php wp_list_pages('sort_column=menu_order&depth=1&title_li=&exclude=340'); ?>

If you see the above code I have added an extra parameter exclude=340, this will tell the WordPress code to exclude the page with id 340 from showing up in the list.

If you want to exclude multiple pages you need to separate each page with a comma, the multiple page excluding code will look the one given below.

<?php wp_list_pages('sort_column=menu_order&depth=1&title_li=&exclude=340,263'); ?>

That’s it once you have made the above changes to the code the page will not appear in the list. Below is a screen shot of the menu after excluding the page from the list.

techie-buzz-menu-fixed [4]

You can use this on your blog too for the pages you do not want to appear in the list. Do let me know if this tip was helpful to you. Your comments are always welcome.

Technorati tags: wordpress [5], blog pages [6], exclude pages [7]

Article printed from Techie Buzz: http://techie-buzz.com

URL to article: http://techie-buzz.com/wordpress/exclude-pages-in-wordpress-list-pages.html

URLs in this post:

[1] how to set up Google custom search: http://www.doshdosh.com/how-to-set-up-google-custom-search-and-make-money/

[2] Image: http://cdn2.techie-buzz.com/images/stories/ExcludePagesinWordPresslistpages_E019/techiebuzzmenu.png

[3] Image: http://cdn2.techie-buzz.com/images/stories/ExcludePagesinWordPresslistpages_E019/managepagewithids.png

[4] Image: http://cdn2.techie-buzz.com/images/stories/ExcludePagesinWordPresslistpages_E019/techiebuzzmenufixed.png

[5] wordpress: http://technorati.com/tags/wordpress

[6] blog pages: http://technorati.com/tags/blog%20pages

[7] exclude pages: http://technorati.com/tags/exclude%20pages

Copyright © 2006-20011 Techie Buzz. All rights reserved.