Imagine I have the following setup:
* Combining Page (Template: Combine Template)
* Sub Page 1 (Template: Basic Template)
* Sub Page 2 (Template: Other Template)
* Sub Page 3 (Template: Basic Template)
So I have three sub pages, two of which have the same template (which uses custom fields as well as regular content). I want the parent page’s template to be able to work like this:
PSEUDO-CODE:
//Show the content for this combine page (e.g. a title)
if ( have_posts() ) : while ...this is the main loop...
$wp_query = new WP_Query();
$all_pages = $wp_query->query( array( "post_type" => "page", "posts_per_page" => -1 ) );
//Get child pages
$child_pages = get_page_children( $post->ID, $all_pages );
//Loop through child pages so we can add their HTML (made from applying their content to their templates)
foreach( $child_pages as $child_page )
{
/** WHAT DO I DO HERE? **/
//Pseudo code
$child_page_template = get_page_template( $child_page->page_name );
$child_output = apply_to( $child_page_template, get_page_content( $child_page->content ) );
}
EDIT
In addition, on the child page, I get a custom field and loop through it:
$values = get_post_custom_values( "mycustomfield" );
foreach ( $values as $value ) echo $value . "<br>";
END EDIT
How would I do this?
Is there anything built in to do this? Or would I need to use output buffers to isolate everything and print each to a buffer from within a function?
It seems like your perspective is just incorrect for the goal you’re trying to reach.
Your pseudo code is reminiscent of a funky iframe style approach. Simply breaking your children pages into what WordPress calls “Template Parts” (basically PHP includes) would be the way to solve this (assuming I understand you correctly). Since Template Parts can be recycled and also have some WordPress-specific benefits when it comes to looping and passing arguments and stuff.