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
- Echo Most Recent Sticky Post in Loop?
- Template included with plugin doesn’t return all posts for custom taxonomy
- Ajax loop and history.js for SEO
- to get a little more content after ‘read more’ inside loop
- Show all child categories associated to post ID within loop
- How to add class and span to
- Remove posts_orderby filter then add it back in
- the_title() Returns the page title instead of the post
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Active class for my flexslider in WordPress
- Issue in If else condition [closed]
- Foundation modal in wordpress php loop
- Link Button url count php and wordpress
- Sorting posts to make those with post thumbnail show up first
- Best way to check if a post with specific meta exists
- ACF field not appearing correctly in loop
- Post gallery as carousel
- Can you create a custom page with content in the center already defined?
- Content template when adding a new page
- Execute php in pages
- pre_get_posts main_query not displaying after applying tax_query filters
- custom page or standalone page?
- Archive sorted by month – separate
- WP update_post_meta link loop
- Avada Theme – Display results from a specific category [closed]
- How to display time when page is created and edited
- WordPress loop only displays 5 articles max?
- Limit article to 100 characters. Can’t use the_excerpt…
- Why isn’t my link attribute getting my css?
- Next 10 posts data of currently viewing post in blog page
- Creating a archive for taxonomy terms, not the term results