我修改了single.php文件以更改每个类别的布局。在single.php我有这个代码如何在wordpress中为不同的类别和子类别创建不同的帖子布局
<?php
$post = $wp_query->post;
if (in_category('26') || get_term_children('26') {
include(TEMPLATEPATH . '/single-ric.php');
}
elseif (in_category('36') || get_term_children('36') {
include(TEMPLATEPATH . '/single-parl.php');
}
else {
include(TEMPLATEPATH . '/single-all.php');
}
?>
这段代码有什么问题吗? 每个帖子文章显示与单ric.php布局
使用'get_template_part('single','all');'代替include(TEMPLATEPATH。'/single-all.php');'。如果我使用'get_template_part'('single','all');'不要使用'TEMPLATEPATH',这是折旧(*如果还没有折旧*) –
该页面仅显示标题而不显示内容。我有同一个文件夹中的所有single.php,single-parl.php,single-all.php和single-ric.php。 – Salvatore
如果get_template_part'找不到模板,那么'get_template_part'会自动失败,所以你可能有其他错误。激活调试模式(将_wp-config.php_中的'WP_DEBUG'常量更改为true)并查看是否显示任何错误。 – vard