【发布时间】:2019-11-07 15:41:35
【问题描述】:
我正在尝试使用以下代码将我的一些帖子从 Single.php 模板重定向到我的 training-v2 自定义模板,但 get_template_part 不起作用。
我的模板是按顺序排列的
themes/theme/templates/training-v2.php
themes/theme/single.php
有人可以帮忙解决get_template_part 结构吗?
<?php
if (have_posts()) : while (have_posts()) : the_post();
$custom_arr = array(6647,6794,6796);
if (in_array(get_the_ID(), $custom_arr)) {
get_template_part( 'themes/theme/templates', 'training-v2' );
}
else {
get_template_part( 'theme/content', 'single' );
}
endwhile; else :
get_template_part( 'parts/content', 'index' );
endif;
?>
【问题讨论】:
-
能否请您分享根文件夹中文件的完整路径,以便我可以帮助您解决此问题。
-
嗨,我的完整路径是 wp-content->themes->theme->templates->training-v2 我的 single.php 路径是 wp-content->themes->theme->single .php