Forums
Home / Fixing WordPress / Display list of child pages
(@will24_)
9 years, 11 months ago
I would like to display a list of child pages under a certain page in the sidebar.
I want to be able to do this by accessing a function or a shortcode and supplying the page ID, like this: <?php display_child_pages(1); ?>
<?php display_child_pages(1); ?>
Is there already an in-built function which does this? If not, how can I code one?
(@shaileshsavaliya)
Try this : http://codex.wordpress.org/Function_Reference/get_pages#Displaying_Child_pages_of_the_current_page_in_post_format
This is for pages….
If you want it for posts than search out for get_posts() function…
(@kenzinser)
You could also use the function wp_list_pages(): http://codex.wordpress.org/Function_Reference/wp_list_pages
wp_list_pages()
And be sure to specify the child_of parameter. Could be defined dynamically, too, based on the current page ID.
child_of
This worked for me:
$args = array('child_of => 391'); // 391 is page ID wp_list_pages($args);