Categories
Development

Display WordPress Child Pages as a List of Links

After figuring this one out, it’s really easy to do but I did have a hard time since I didn’t bother to check and see if a specific function already existed to do this behavior.

I wanted to display all the child pages of a Page as an unordered list. I initially tried using the WP_Query function to make this work. I tried creating a loop and feeding it some parameters, but kept getting no results.

Upon some further searching I did come across the wp_list_pages() function. I’m not sure why I didn’t begin with this, but for some reason I was set on using WP_Query.

There’s a ton of parameters and some great examples found on the wp_list_pages() page.

Here’s the little bit of code I added to a template to output the child pages as a list. Notice that the parent page’s id is the 32 that you will see as a parameter below. Enter whatever your parent page’s id is in it’s place.

wp_list_pages('sort_column=menu_order&title_li=&child_of=32');

Doesn’t really get much easier that that.

Leave a Reply

Your email address will not be published. Required fields are marked *