在自己的页面模板中同时显示多个页面


Show multiple pages at once in their own page template

我正在构建一个单页网站。因此,多个页面同时显示在首页上。我按它们在主菜单中的位置点餐。一切都很好,但要以更具活力的方式实现这一点。我想在自己的页面模板中输出每个页面。

这可能吗?我将如何实现?

到目前为止,我的方法首页.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;
?>

你可以试试这个:

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

请记住,您必须从这些模板中删除循环之外的所有内容,因为您在调用front-page.php allready中提供了这些内容。请确保front-page.php从未在循环内部调用过,因为这将导致一个无休止的循环。