I have a need to make the Loop run through all of the children of a parent, all of the children of each child, etc. The reason I need the Loop instead of a listing tag like wp_list_pages is so that I can display any information associated with the pages using WP template tags and functions. It's for a showcase-style display that has hierarchical content and gets rearranged, so pages > posts for this usage.
I've gotten as far as getting the loop to show children of the current page and an inner loop going to show grandchildren, but this is just a brute-force prototype, and I need to take it to the next level.
What I think I need to do is use 1 loop that starts with post_parent (so that it shows child pages) but insert a function to change the post ID to each child page found so that the loop continues to drill down until it runs out, then backs out 1 level, goes to the next available ID, etc.
My problem is that I'm not enough of a WP programmer (or real programmer at all) to get that going. If it were all out in code I bet I could work it out, but WP has obviously got hidden functions going with have_post and the_post to cycle through the available post IDs, and that has me lost as to how to integrate what I need.
Here's where I am at the moment. Any help will be greatly appreciated!
<?php
$args = array(
'posts_per_page' => -1,
'post_parent' => $post->ID,
'post_type' => 'page',
'post_status' => '',
'orderby' => 'title',
'order' => 'ASC',);
query_posts($args); ?>
<?php if(have_posts()) : while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink();?>"><?php the_title();?>:</a>
<?php $inner_query = new WP_Query("post_type=page&posts_per_page=-1&post_parent={$id}&order_by=title&order=ASC"); ?>
<?php while ($inner_query->have_posts()) : $inner_query->the_post(); ?>
<a href="<?php the_permalink();?>"><?php the_title();?>:</a>
<?php endwhile; // end inner loop ?>
<?php endwhile; //end outer loop ?>
<?php endif; // end outer if have_posts?>