Skip to content

Instantly share code, notes, and snippets.

@bmsterling
Created August 31, 2012 04:34
Show Gist options
  • Save bmsterling/3549100 to your computer and use it in GitHub Desktop.
Save bmsterling/3549100 to your computer and use it in GitHub Desktop.
Wordpress: List all children pages and include the parent page
$child_of = 0;
if (empty($post->post_parent)){
$child_of = $post->ID;
}
else {
$child_of = $post->post_parent;
}
// Set defaults
$defaults = array(
'class' => $tag,
'depth' => 0,
'show_date' => '',
'date_format' => get_option( 'date_format' ),
'exclude' => '',
'include' => '',
'child_of' => $child_of,
'title_li' => null,
'authors' => '',
'sort_column' => 'menu_order, post_title',
'sort_order' => '',
'link_before' => '',
'link_after' => '',
'exclude_tree'=> '',
'meta_key' => '',
'meta_value' => '',
'offset' => '',
'exclude_current_page' => 0
);
$pages = get_pages($defaults);
$pageids = array($child_of);
foreach ($pages as $page) {
$pageids[]= $page->ID;
}
$defaults['include'] = implode(',',$pageids);
wp_list_pages( $defaults );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment