Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
将我的文章从single.php导航到自定义模板_Php_Wordpress - Fatal编程技术网

将我的文章从single.php导航到自定义模板

将我的文章从single.php导航到自定义模板,php,wordpress,Php,Wordpress,我在我的网站上有一些帖子是通过single.php发布的,现在我有了一个新页面。其中有一些帖子我想使用自定义模板,但我的帖子是single.php模板。有人能帮我写一些代码吗?我可以用single.php编写,这样我就可以用post ID导航了。在我的自定义模板中,我应该用什么代码来构建它?single.php <?php get_header(); ?> <div id="primary" class="content-area"> <m

我在我的网站上有一些帖子是通过single.php发布的,现在我有了一个新页面。其中有一些帖子我想使用自定义模板,但我的帖子是single.php模板。有人能帮我写一些代码吗?我可以用single.php编写,这样我就可以用post ID导航了。在我的自定义模板中,我应该用什么代码来构建它?

single.php

<?php get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <?php
            if (have_posts()) : while (have_posts()) : the_post();

                $custom_arr = array(1,2,3,4);
                if (in_array(get_the_ID(), $custom_arr)) {
                    get_template_part( 'parts/loop', 'single-custom' );
                }
                else {
                   get_template_part( 'parts/loop', 'single' ); 
                }

            endwhile; else :

                get_template_part( 'parts/content', 'missing' );

            endif;
            ?>
        </main><!-- #main -->
    </div><!-- #primary -->

<?php get_footer(); ?>

然后创建两个单独的文件
/parts/loop single.php
/parts/loop single custom.php

您可以通过自定义类别或post上的自定义字段进行检查,而不是通过id进行映射,硬编码id的数组这只是一种糟糕的做法