The snippet from codex is a bit redundant in your case. You can achieve what you need, by using snippets like these:
index.php
$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() ) :
$the_query->the_post();
echo '<section class="page' . get_the_ID() . '">';
get_template_part( 'foo', $index++ % 3 + 1 );
echo '</section>';
endwhile;
wp_reset_postdata();
foo1.php
<div id="template-foo-1">
<?php the_content() ?>
</div>
foo2.php
<div id="template-foo-2">
<?php the_content() ?>
</div>
foo3.php
<div id="template-foo-3">
<?php the_content() ?>
</div>
Related Posts:
- Is including the loop necessary for page.php? [duplicate]
- Loop and Page template : my WP_query don’t take args
- Print the whole page?
- get_template_part() to render single page Theme
- Getting only direct child pages in WordPress with get_pages
- Do I need to use The Loop on pages?
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Child Pages Loop
- Get post by page name or slug
- Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content
- Display subpages under parent page as a list within a loop
- When and Why is is_singular(‘my_cpt’) true while in_the_loop() is false?
- Identify the page being shown while in The Loop
- Trying to list out child pages with WP_Query
- loop not showing up when using a custom page template
- If Loop has odd number of posts on last page Custom style for last post in it
- Custom page template
- Getting page ID inside loop
- single page site with subpages
- How to loop through ALL pages?
- Get Pagination (WP-PageNavi) not to work
- Display content of page template (get_page)
- Loop after page content
- wp alchemy multiple image uploader output images to template
- Running a loop with a custom query string on a custom page template
- How to load all pages into one page with their templates
- How to hide all child pages with post_query?
- Get Page content to displayin Bootstrap Modal
- Custom Loop Using Shortcode in Custom Page Template
- Do I need to use The Loop on pages?
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- How do I make a variable available inside partials?
- Multiple get_posts() queries on one page
- Exclude page name from loop
- Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
- Include multiple page ids in loop
- Get post offset/posts page offset in single post page (outside the loop)
- First archive page with a few posts
- Tags on page (not post) returns nothing – why? Improved clarified question!
- Exclude page from loop results
- excerpt not showing up
- WP_Query is only looping home page, not pages
- Interrogate a page within a loop to check template type or custom meta data (Pages vs Posts)
- How do i create a list-posts-page?
- Static Website No Titles But Still Nav
- WordPress: query pages except remove one page
- Custom Header added within Dashboard pages, is this possible with custom template files?
- How to use custom page for all posts with custom url, call another directory?
- Duplicated tag in loop
- get the value for ALT is we check to see if an actual ALT value is set, if not we use the caption and if no caption is set we use the title
- Archive: Lists itself
- My WordPress installation doesn’t load correct template
- is it bad to copy the loop for a template?
- Get top Page IDs from menu and cycle through their child pages on a scroller
- Problem with Displaying Custom Theme Page’s Content
- Search – Check if post is a page on search page
- Structure and Display Content from Multiple Pages on Single Page
- Making a specific page wordpress compatable that is not index
- Default Template infinite loop of Title
- Have multiple loops on a page appear after/between page content
- Display articles related to a custom field on a page
- Stuck with conflicting loops on page template
- Same Loop on Multiple Pages
- Loop not showing up on page template
- Custom Page Template and Category Exclusion
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- Display all posts in a page code for template
- Get post content from outside the loop
- is_home, and is_front_page conditional problem
- Is `query_posts` really slower than secondary query?
- Display date only once for a each set of posts relating to that date
- Combining the_excerpt with the_content
- Query reset problem or flawed code to enable custom post type query
- Removing the TinyMCE editor for a given page template
- Exclude posts from main loop based on meta value
- trouble calling an import class from an action in a plugin before wp_cron executes
- How to fix pagination for custom loops?
- How to include custom post type posts on a page?
- JQuery Plugins in WordPress
- Escape current post from loop
- Why isn’t my multiple loops working?
- facebook like, tweet and google+1 buttons inside the loop on home, archive and search pages and missing facebook like buttons
- How do I edit text displayed on my browser tab?
- How to print redux gallery feilds id? [closed]
- Why the first with flexslider appears as blank on my code?
- Rendering pages
- How to add pages in wordpress using codes?
- How does the loop know which post to view?
- How can have a conditional template tag based on the main loop within a secondary loop with new WP_Query(), using get_template_part()
- WordPress Page doesn’t load the template selected
- How to filter posts by category INSIDE the loop
- Custom folder for wordpress page templates
- Adding a second loop breaks everything
- I want to load post in bootstrap Modal dynamically
- Return only one post format in index.php [duplicate]
- How to execute custom loop before loop content?
- Return only content in excerpt field in loop
- get_posts and wp_autop (remove filter)
- Trouble preventing duplicate posts between 2 loops on homepage
- wp_mail function not working in user query loop