WordPress plugins, themes, tips and hacks

List only child Pages of a specific parent Page

May 9, 2007 – 5:12 pm | by Miriam Schwab

I am building a site for a client, and I want to list all the child Pages, which will be many, of one of their parent pages in the sidebar. To help you understand better, this client provides many services, so I wanted there to be a parent Page called “Services,” and this parent Page will have a list of child Pages, each of which goes into detail about each specific service.

I couldn’t find any information on how to do this, but then I came across a tag for categories that allows you to only list the subcategories of a specific category. This tag is as follows:

<?php wp_list_cats('child_of=8, 14'); ?>

By using this tag, you would only list the child categories of the categories with IDs of 8 and 14. So I decided to see if this would work with Pages, and it did!

So here’s the code I put in the sidebar to list only the child Pages of the Services Page, sorted alphabetically and omitting the title of “Pages”:

<?php wp_list_pages('child_of=2&sort_column=post_title&title_li=') ?>

Hurray!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related posts

  1. 17 Responses to “List only child Pages of a specific parent Page”

  2. By Brad on May 24, 2007 | Reply

    FABULOUS WORK!!

    I have never been to this site before, but your most recent insight into listing the child pages to a specific parent page works GREAT!

    Wonderful in sharing your findings.

  3. By Miriam on May 25, 2007 | Reply

    Thanks Brad! I’m glad that this information helps you. Hope to see you again!

  4. By Glen on Jul 5, 2007 | Reply

    Nice spot, been trying to figure this out all day before stumbling upon your post! Many thanks for the info.

  5. By Miriam on Jul 5, 2007 | Reply

    Glen - glad to help!

  6. By Alvin on Jul 13, 2007 | Reply

    I’m trying to do this within a page rather than on the sidebar. I tried the code, but it didn’t work. Any thoughts?

  7. By Alvin on Jul 13, 2007 | Reply

    Hey, I figured it out. I had to put the code in a php file, not in the actual page. I’m just an attorney, so it takes me a while to figure things out. But the code works. Thanks.

  8. By Miriam on Jul 13, 2007 | Reply

    Alvin - don’t be too hard on yourself - lawyers can do anything! That’s why we all love them.

    Glad you figured it out and that it has helped you!

  9. By Luigi on Sep 1, 2007 | Reply

    Is there a way to categorize pages or sub-pages, and be able to place those categories in a drop down menu to select different sub-pages ?

  10. By Miriam on Sep 1, 2007 | Reply

    Hi Luigi - cool blog! Do you want to be able to place Pages - i.e. the pages on a blog that are outside of the blogging loop, like the About page here for example - in categories? If so, I’ve never come across a way to do that. If you want to create drop-down menus for categories, I have seen plugins that do that kind of thing. Try searching on Google. If I come across those plugins, I’ll try to remember to let you know.

  11. By Luigi on Sep 2, 2007 | Reply

    thanks Miriam.
    That was my prob….I know how to do create the drop down menu for the normal categories.

    But in WP, they are only associated to posts and not to pages.

    I need to categorize pages to make the Album pages available for browsing not only by genre (classical or Jazz) but also for kind of music ensamble (quartet, quintet, orchestra).
    This could be sub-categories of the main categories: jazz and classical

  12. By Miriam on Sep 3, 2007 | Reply

    Good news Luigi! I just came across a plugin that enables you to categorize Pages: Page Category Organiser. I probably would have ignored it if you hadn’t asked your question.

    I haven’t tested it out, so I don’t know how well it works, so please can you let me know once you’ve tried it out? Thanks.

  13. By Luigi on Sep 3, 2007 | Reply

    Hi Miriam,
    I already tested that plugin.
    It has some bugs …. and it’s only possible to assign one category to each page.

    I need to give more than one :(

    More, it does not seem to create permanent links for page category….

  14. By sebas on Oct 23, 2007 | Reply

    great, but how can i only display only first childs of that page??

    depth=1

  15. By Anne on Jan 31, 2008 | Reply

    Thank you, that worked like a charm!

  16. By Miriam Schwab on Jan 31, 2008 | Reply

    Hey Anne - glad to help.

  17. By Sue @ TameBay on Mar 28, 2008 | Reply

    Worked like a charm for me too - thanks Miriam!

  18. By Remon on Apr 25, 2008 | Reply

    Great article… it helped me figure out a different problem.  Thanks

Post a Comment

Revolution Premium Themes