2014-10-08 59 views
1

我正在构建单页网站。因此,多个页面一次显示在首页上。我按照他们在主菜单中的位置排序。一切都很好,但要以更加动态的方式实现这一目标。我想输出他们自己的页面模板中的每一页。在自己的页面模板中一次显示多个页面

这是可能的,我将如何实现这一目标?

到目前为止我的做法 - 前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; 
?> 

回答

1

你可以试试这个:

<?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中已经提供了这个。并确保front-page.php从不在循环内调用,因为这会导致无限循环。

+0

这就像一个魅力 - 非常感谢。 – retober 2014-10-08 13:44:05