I am creating a template that would display children pages of a parent page.
Employees
♦ Managers
♦ IT guys
♦ Designers
I want parent page (employees) to display its children pages.
I've tried this: (in functions.php)
function wpb_list_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
if ( $childpages ) {
$string = '<ul>' . $childpages . '</ul>';
}
return $string;
}
add_shortcode('wpb_childpages', 'wpb_list_child_pages');
and declaration in my page's template:
echo wpb_list_child_pages();
I get a list of children pages but as a list (of course, there is nothing wrong with the code)
I want to enlist children as items of an array so that I can do something like this:
$page1 = childrenID[0];
$page2 = childrenID[1];
$page3 = childrenID[2];
I want this so that I can theme children pages (by ID) on their parent page.
I hope I am clear.
Update
After using this: `global $post; $parent_id = the_ID();
$children = get_posts(array( 'post_parent' => $parent_id, 'fields' => 'ids' ));
echo $string = '
I am getting a list of IDs which are of some posts and not pages.