Working with Pages in WordPress

on September 26th, 2006 | Filed under Common Theme Issues, WordPress Tips

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.

I will come back with more tips later.
Thats all for now, folks.
Thanks.

13 Comments

13 Responses to “Working with Pages in WordPress”

  1. adam says:

    my favorite tip is “how can i add links to my (flickr/myspace/last.fm/vox) in the navigation menu?”

    to which the answer is:
    http://txfx.net/code/wordpress/page-links-to/

    🙂

  2. Sadish says:

    Oh,
    thats nice to know.

    Thanks for sharing it Adam.

    Sadish

  3. Rita says:

    I wrote earlier with a question about how to integrate an RSS feed into one of your themes, but I apologize for forgetting to mention which one. I was interested in doing this with the new TerraFirma 2.0 theme. It would be nice if you could add at least a comment to the sidebar or footer template to let us know how and/or where to add an RSS feed.

    Thank you for any assistance you can provide to a newbie.

  4. Sadish says:

    The latest version of the terrafirma theme has the feeds implemented on the sidebar.
    please check it out at http://wpthemepark.com/themes/terrafirma/

    I moved your earlier comment also in there. (Thats the right location for it, isnt it ? )

    Sadish

  5. Jackie Bell says:

    I have spent days trying to figure out how to display “Pages” (and their children) differently in the sidebar. For example on this page – how would you NOT show the four children underneath “Themes” until “Themes” was clicked?
    I have several “Parent” pages with long lists of children that I’d prefer not show unless the parent was selected.
    I have tried two different plugins and cannot get them to work on these four themes. On themes where there is no top navigation bar they work like they are supposed to work.
    If I could just get past this display issue your themes would be perfect for me.
    Thanks!

  6. Leon says:

    Hi Jackie

    I had this problem with another theme that didn’t show child pages but I used the function from k2 and coded that into the theme, now the child pages only show when the Parent page is loaded (is that what your after ?)

    Something like this in the ‘sidebar’:
    ID;
    while($current_page) {
    $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
    $current_page = $page_query->post_parent;
    }
    $parent_id = $page_query->ID;
    $parent_title = $page_query->post_title;
    if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) {
    ?>

    ID) { ?>
    ">

    Not sure if all the above code is necessary as I just messed with it until it worked.

    It now loads the ‘child’ pages at the bottom of the sidebar menu when the relevent parent page is loaded.

    Hope that helps.

    Leon

  7. Hi Sadish,

    I created an about page with a default page and the footer css is out of whack. Is there a place I should be modifying this?

    Thanks.

    Jonathan

  8. Sadish says:

    Jonathan.
    Start here.
    Validate

    Thanks

  9. thanks for the help, I have been looking for this for about 2 hrs

  10. […] and finally selected something very simple.  If you still want more templates there are a lot of free ones out there. Once I selected a themse I got another sub menu which had theme editor .  Great I […]

  11. shunichirou says:

    hi, thanks for your tips!
    it really helps me

    i’ve been wandering the net to find how to hide pages 🙂

    thanks so much!

  12. This will improve my wordpress blog a lot. Thx for all those usefull tips and tricks.

  13. kakaz357 says:

    Home and About me navigation buttons show the same page and act like one button. i.e when you click one both show as clicked. I only need the about me button as there is another home button.

Leave a Reply