0

I'm trying to get my head around this issue I have and the only way I can think about doing it is pulling in things via a WP_Query but you can't have a query inside a query can you?

What I'm trying to do is the following:

  • Main Top Level Page
    • Sub page
      • Sub, sub page

So what I'm trying to achieve is have a page that lists all of its sub pages (children) but then also display all the children of the first child page. Essentially like a list of categories and items within said category.

All I'd need is the link and name of the sub pages and then the link, name and featured image of the sub, sub pages.

Can anyone help me on where to get started please?

1 Answer 1

0

Will get_pages() work for you? http://codex.wordpress.org/Function_Reference/get_pages

If I'm understanding your question correctly, you would want something like this:

$children_of_page = get_pages(array(
    'child_of' => $post->ID,
    'parent' => $post->ID  //defining both parent and child forces the list to only include direct children.
));
$children_of_first_child = get_pages(array(
    'child_of' => $children_of_page[0][ID],
    'parent' => $children_of_page[0][ID]
));

If you wanted to output a list directly, you could use wp_list_pages(), http://codex.wordpress.org/Template_Tags/wp_list_pages, something like:

wp_list_pages(array( //Get first level children of current page and output as list
    'child_of' => $post->ID,
    'depth' => 1,
    'title_li' => ''
));
$children = get_pages(array(
    'child_of' => $post->ID,
    'parent' => $post->ID
));
wp_list_pages(array( //output the children of the first child
    'child_of' => $children[0][ID],
    'depth' => 1,
    'title_li' => ''
));

Mess with the arguments as needed to get exactly what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.