WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make a template that will be an html5/ vertical scrolling base.

I have created an amount of page templates that each would represent a <section> on index.php which mainly all it does is to retrieve the child pages of a page I named ROOT using this:

// Set up the objects needed 
$my_wp_query = new WP_Query(); 
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));

// Get the page as an Object 
$mainpage =  get_page_by_title('ROOT');

// Filter through all pages and find Portfolio's children 
$children = get_page_children( $mainpage->ID, $all_wp_pages );

Is there a way to render the output with the each page template? The page hierarchy is like this:

- Page1 (template: foo1)
- Page2 (template: foo2)
- Page3 (template: foo3)
- Page4 (template: foo1)

so what I am trying to achieve is to have an output like this:

<section class='page<?php the_ID(); ?>'>
[content with template foo1]
<section class='page<?php the_ID(); ?>'>
[content with template foo2]
<section class='page<?php the_ID(); ?>'>
[content with template foo3]
<section class='page<?php the_ID(); ?>'>
[content with template foo1]
share|improve this question
up vote 2 down vote accepted

The snippet from codex is a bit redundant in your case. You can achieve what you need, by using snippets like these:


$mainpage = get_page_by_title( 'ROOT' );
$the_query = new WP_Query( array(
    'post_parent' => $mainpage->ID,
    'post_type'   => 'page',
) );

$index = 0;
while ( $the_query->have_posts() ) :
    echo '<section class="page' . get_the_ID() . '">';
    get_template_part( 'foo', $index++ % 3 + 1 );
    echo '</section>';



<div id="template-foo-1">
    <?php the_content() ?>


<div id="template-foo-2">
    <?php the_content() ?>


<div id="template-foo-3">
    <?php the_content() ?>
share|improve this answer
Not a bad approach, but I went with creating shortcodes that would deliver the html necessary for each section. Nevertheless, it is helpful for another project I have in mind. – Panagiotis Feb 20 '13 at 13:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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