【发布时间】:2015-12-30 05:45:31
【问题描述】:
我有 1 个单独的帖子页面模板,它将显示 2 个不同的分类术语,我喜欢为这 2 个不同的术语调用 2 个不同的侧边栏。这个帖子模板是“single-recipe.php”,我称之为“content-single_recipe.php”。在“content-single_recipe.php”中,我根据条件语句的不同条款调用了 2 个不同的侧边栏:
SINGLE-RECIPE.PHP
while ( have_posts() ) : the_post();
get_template_part( 'content', 'single_recipe' );
endwhile; // end of the loop.
CONTENT-SINGLE_RECIPE.PHP
php the_content();
// Here are code for sidebars:
$term = get_the_term_list($post->ID, 'recipe_type');
if ( $term = 'salad' ){
dynamic_sidebar('sidebar-salad');
}elseif($term = 'sandwich'){
dynamic_sidebar('sidebar-sandwich' );
}
但是,无论 $term 是什么,它总是称为“sidebar-salad”。
【问题讨论】: