使用页面模板将所有Wordpress页面拉入一个页面

使用页面模板将所有Wordpress页面拉入一个页面,wordpress,Wordpress,我想能够从我的自定义主题拉到一个页面模板的所有页面,但仍然允许所有的页面显示根据选定的页面模板 换句话说,如果我有一个名为“Main”的页面模板,我将所有页面数据拉入其中,并创建一个名为“Home”的页面,我希望该页面根据我为“Home”页面选择的页面模板显示在“Main”模板上。这可能吗 谢谢, JW在所有页面模板中使用以下内容: include 'page.php'; 然后在page.php中,您可以使用: if (is_page_template('page_temp_one.php')

我想能够从我的自定义主题拉到一个页面模板的所有页面,但仍然允许所有的页面显示根据选定的页面模板

换句话说,如果我有一个名为“Main”的页面模板,我将所有页面数据拉入其中,并创建一个名为“Home”的页面,我希望该页面根据我为“Home”页面选择的页面模板显示在“Main”模板上。这可能吗

谢谢,
JW

在所有页面模板中使用以下内容:

include 'page.php';
然后在page.php中,您可以使用:

if (is_page_template('page_temp_one.php')) { ... }

在所有页面模板中使用以下内容:

include 'page.php';
然后在page.php中,您可以使用:

if (is_page_template('page_temp_one.php')) { ... }

好的,我将在这里回答我自己的问题。我自己做了一些研究,并修改了教程中的一些代码,使主题成为Ajaxify。需要做的就是这样

在您的page.php文件中,或者您想要用作主页面模板的任何模板中,添加以下内容

<?php query_posts( array('post_type'=>'page', 'posts_per_page' => 1000, 'orderby' => 'menu_order', 'order' => 'ASC') ); ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>

    <?php 
        global $post;
        $slug = $post->post_name;
        locate_template(
            array(
                "template-$slug.php",
                'template-main.php'
            ), true
        );
    ?>
<?php endwhile; endif; ?>


然后将页面模板添加到主题中,并根据页面slug命名,即template-about.php或template-home.php。然后,您可以在一个页面站点中动态显示所有内容,并可以使用默认的Wordpress页面。我希望我已经清楚了这一点,如果没有,请随时让我知道,我会尽最大努力澄清

好的,我在这里回答我自己的问题。我自己做了一些研究,并修改了教程中的一些代码,使主题成为Ajaxify。需要做的就是这样

在您的page.php文件中,或者您想要用作主页面模板的任何模板中,添加以下内容

<?php query_posts( array('post_type'=>'page', 'posts_per_page' => 1000, 'orderby' => 'menu_order', 'order' => 'ASC') ); ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>

    <?php 
        global $post;
        $slug = $post->post_name;
        locate_template(
            array(
                "template-$slug.php",
                'template-main.php'
            ), true
        );
    ?>
<?php endwhile; endif; ?>

然后将页面模板添加到主题中,并根据页面slug命名,即template-about.php或template-home.php。然后,您可以在一个页面站点中动态显示所有内容,并可以使用默认的Wordpress页面。我希望我已经清楚了这一点,如果没有,请随时让我知道,我会尽最大努力澄清