Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Page.php覆盖自定义页面模板,然后使用get_Template_part()调用自定义页面模板_Php_Wordpress_Templates - Fatal编程技术网

使用Page.php覆盖自定义页面模板,然后使用get_Template_part()调用自定义页面模板

使用Page.php覆盖自定义页面模板,然后使用get_Template_part()调用自定义页面模板,php,wordpress,templates,Php,Wordpress,Templates,我想对所有页面使用page.php(因此我不必在所有页面模板中重复例如get_header()和#section top),然后使用get_template_part()调用基于页面模板的内容。现在我有我的page.php和两个内容部分,一个被设置为标准的“content flexible.php”(如果没有设置页面模板),另一个用于显示帖子“content posts.php” 这是我的page.php文件: <?php get_header(); ?> <main id="

我想对所有页面使用page.php(因此我不必在所有页面模板中重复例如get_header()和#section top),然后使用get_template_part()调用基于页面模板的内容。现在我有我的page.php和两个内容部分,一个被设置为标准的“content flexible.php”(如果没有设置页面模板),另一个用于显示帖子“content posts.php”

这是我的page.php文件:

<?php get_header(); ?>
<main id="page-main" role="main" class="main">
        <?php 

        ?>
    <section id="section-top" class="header cf">        
            <h2><?php the_title(); ?></h2>
    </section>
    <div id="content-wrap" class="wrap cf">
            <div id="inner-content" class="wrap cf">
            <?php 
                //Use page-templates for content
                if( $post->post_parent !== 0 ) {
                    get_template_part('page-parts/content', 'posts');
                } else {
                get_template_part('page-parts/content', 'flexible');
                }
            ?>
            </div>  <!-- /inner-content -->
    </div> <!-- end /content-wrap -->   
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

现在else语句可以工作(调用content-flixible.php),但是当我将页面模板设置为“Posts Page”时,它只使用content-Posts.php,因为它遵循WordPress的正常层次结构。我如何重写它,使我始终使用“page.php”仅根据管理页面中使用的页面模板交换内容