将我的文章从single.php导航到自定义模板
我在我的网站上有一些帖子是通过single.php发布的,现在我有了一个新页面。其中有一些帖子我想使用自定义模板,但我的帖子是single.php模板。有人能帮我写一些代码吗?我可以用single.php编写,这样我就可以用post ID导航了。在我的自定义模板中,我应该用什么代码来构建它?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
<?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的数组这只是一种糟糕的做法