Show multiple pages at once in their own page template

I’m building a single page website. So multiple pages are shown at once on the frontpage. I order by their position in the primary menu. Everything is fine but to achieve this in a more dynamic manner. I would like to output every page in their own page-template.

Is this possible and how would i achieve this ?

Read More

My approach so far –
front-page.php

<?php
if (($locations = get_nav_menu_locations()) && $locations['primary']) {
    $menu       = wp_get_nav_menu_object($locations['primary']);
    $menu_items = wp_get_nav_menu_items($menu->term_id);
    $pageID     = array();
    foreach ($menu_items as $item) {
        if ($item->object == 'page')
        $pageID[] = $item->object_id;
    }
    query_posts(array(
    'post_type' => 'page',
    'post__in' => $pageID,
    'posts_per_page' => count($pageID),
    'orderby' => 'post__in'
    ));
}
while (have_posts()):   the_post();
//LOOP - INSERT SOLUTION HERE
//Show all pages in their own or default page template (page.php, page-portfolio.php ...)
endwhile;
?>

Related posts

Leave a Reply

1 comment

  1. You can try this:

    <?php
    while (have_posts()):   the_post();
        $page_template = get_page_template_slug( get_the_ID() );
        get_template_part( basename($page_template, ".php"));
    endwhile;
    
    ?>
    

    Remember that you have to remove all the stuff outside the loop from those templates, since you provide this in the calling front-page.php allready. And be sure that the front-page.php never called inside the loop, because this will result in a endless loop.