List only child Pages of a specific parent Page
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!
Category: WordPress as CMS










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.
Thanks Brad! I’m glad that this information helps you. Hope to see you again!
Nice spot, been trying to figure this out all day before stumbling upon your post! Many thanks for the info.
Glen – glad to help!
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?
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.
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!
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 ?
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.
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
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.
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….
great, but how can i only display only first childs of that page??
depth=1
Thank you, that worked like a charm!
Hey Anne – glad to help.
Worked like a charm for me too – thanks Miriam!
Great article… it helped me figure out a different problem. Thanks
finally!
thanks so much man, i was looking for this for a while and it turns out to be really simple
thanks
You’re welcome Dejan! Glad to help.
Thank you, this was very helpful! I thought I might also offer the additional tweak I wound up with, for other readers: making the parent page the title list item. It turns out to be just one extra line of code.
<code>$home = wp_list_pages(‘include=483&title_li=&echo=0′);
wp_list_pages(“child_of=483&title_li=” . $home );</code>
Cheers
[...] List only child Pages of a specific parent Page – how to list all the child Pages of the current page in the sidebar [...]
hi!
please, help me: how can i display children page only when click on link of parent page? — i want only parent pages to be displayed when generates list of pages
This is exactly what I was looking for!
Hi,
I haven’t tried out your solution yet, or the subsequent ones either, I’m wondering if this thing can be applied to a SPECIFIC page, and not all pages. Because its not clear if this solution is for all pages…which I don’t want. I want it for one specific page.
Thanks!
just wanted to say that i’ve come across your site numerous times after searching google for certain solutions and every time, i find what i’m looking for here. it’s got to the point where i see your site come up, i pretty much know whatever you suggest in a post will work. this post is a great example. thanks!
Thanks so much for the positive feedback Paul! I’m so glad that you find our posts useful.
wow wow wow lol many thanks, exactly what i’ve been searching for a couple days now
any idea if I can make the output wrap every child into a <h4> tag instead of a <li> tag?
I just struggled with this for an hour, and you gave me the clue I needed. Thanks!
If you want a page to show a list of it’s own children, this is the template/theme code:
<?php wp_list_pages(‘child_of=’.$post->ID.’&sort_column=post_title&title_li=’) ?>
You saved my sanity. I’ve been trying to figure this out for 2 days. Thank you thank you thank you.
Ha! Nice work Miriam :) Glad I landed up here early hehe.
Awesome tip. Posted quite awhile ago but still helping people out! Thank you!
You are a lifesaver!! I have been looking for this code for the past 3 hours! Thank you very much!
just what i needed…. although… is there a way to use the page name rather than the page id? the reason is, i test it out locally via MAMP, and then when i upload to server, i have to change all of the ids to match the page ids on the server… keeps it from being able to be synchronized.
Thank you,
I found, what I am searching?
Hi
I got this working no problem, thanks a lot. However, I would also be wanting to add <strong></strong> elements within the link for the child page. So..
<ul><li><a href=”#”><strong>Child Page</strong></li></ul>
Any chance you would know how to do this?
Thanks in advance!
I really have been busy for 2 full hours to get the subpage shown on the parent page. All the other forums weren’t doing the trick, because the ‘while($recent->have_posts..’ was blocking somethng.
So after 2 hours, your simple code worked for us!
@ Justin Sternberg- if you got to Settings> Permalinks, you have a choice to explicitly set the id’s of the pages so the migration should be very easy.
Thank you very much for this useful tip! I have a secondary navigation in my footer that lists all the child pages and I was searching for a way to make it dynamic as well. Well done!
Thank you a ton! That helped me out perfectly!!
@Gray… thank you for your reply… i checked the permalinks settings but do not see that option to explicitly set the id’s of the pages. see screenshot
—> http://drp.ly/1vKC5s
@ Justin Sternberg from what I understood you wanted to change the default id’s to the page names, right? Well, from the screenshot you just sent, if you select Custom Structure, that will automatically change the ids to the names of your page. I found that /%category%/%postname%/ was most ideal.
Hope that helps!
@Gray ok, now i understand what you’re saying… thank you! so, to get this to work, replace:
<ul class=”children”>
<?php
if($post->post_parent)
$children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
else
$children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
if ($children) {
?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
</ul>
with:
<ul class=”children”>
<?php
if($post->post_parent)
$children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
else
$children = wp_list_pages(“title_li=&child_of=”.$post->MyPageName.”&echo=0″);
if ($children) {
?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
</ul>
?
@Gray ok, now i understand what you’re saying… thank you! so, to get this to work, replace:
<?php wp_list_pages(‘child_of=2&sort_column=post_title&title_li=’) ?>
with:
<?php wp_list_pages(‘child_of=MyPageName&sort_column=post_title&title_li=’) ?>
?
Hi,
i see you are the pages specialist
i have the following problem: I want to have the pages in another DIV then the subpages of the selected page. (see a drawing of the problem)
I hope you can help,
Bas