Working with Pages in WordPress

Posted by admin

WordPress allows you to create ‘Pages’ within the wordpress blog.
Anytime you want to write something like an about page / a contact page / an article page, you would use this feature.

Most of our themes displays a list of pages as navigational elements at the top. We use the wp_list_pages() method, so any new page you create, will automatically display in that navigation.

I would like to present a few of the most common questions people ask, when they use one of our themes.

  1. How to hide certain pages from the navigation ?
  2. How to display the pages in a different order ?
  3. Why is my child page, is not listed in the navigation ? etc.


wp_list_pages() – is the wordpress method that generates a list of ‘links to pages’.
Something like

<li class="page_item"><a href="http://wpthemepark.com/about/" title="About">About</a></li>
<li class="page_item"><a href="http://wpthemepark.com/archives/" title="Archives">Archives</a></li>
<li class="page_item"><a href="http://wpthemepark.com/contact/" title="Contact">Contact</a></li>

We can call this method using different set of arguments.

Lets look at the Question 1 :

How to hide certain pages from the navigation ?

Suppose you wanted to hide ‘about’ and ‘contact’ pages from the top navigation.
1. You login to your wordpress blog, and go to ‘Manage’ -> Pages
2. You would see the list of all pages you created.
3. Note down the Page Ids, the numbers on the left side of the Page Names, like 2 and 4.
4. Now we have to modify the call to wp_list_pages in the header.php (Have a backup of this file if you want to go back to the original state) .
5. Find wp_list_pages within this file.
6. Add an additional argument “exclude=2,4” to that.

<?php wp_list_pages('title_li=&depth=1&exclude=2,4');?>

Thats it. These pages will not get displayed in the top navigation.

Lets look at the Question 2 :

How to display the pages in a different order ?

1. You login to your wordpress blog, and go to ‘Manage’ -> Pages
2. Click on ‘Edit’ on the page you wanted to be first in the navigation.
3. On the right hand side, you will see ‘Page Order’ box.
4. Expand that box, enter ‘1’ as the value.
5. Again go back to ‘Manage’ – > Pages
6. Click on Edit on the page you wanted to be second in the navigation
7. On the right hand side, enter ‘2’ for the Page Order.
8. Now we have to modify the call to wp_list_pages in the header.php (Have a backup of this file if you want to go back to the original state) .
9. Find wp_list_pages within this file.
10. Add an additional argument “sort_column=menu_order” to that.

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

Thats it. Your Pages list will be sorted in that order.

Lets look at the Question 1 :

Why is my child page, is not listed in the navigation ?

Because our themes are defined in such a way that it only displays top level pages in the navigation.

You might have seen “depth=1” as an argument in the examples presented above.This argument makes the child pages to be not displayed in the top navigation.

Thats all for now, folks.
[Reposted from one of my other sites]

No responses yet

Please use the sidebar for navigating within the Book.