我有两种自定义的帖子类型,一种是视频帖子,另一种是图库帖子,还有一种自定义的分类法状态帖子,其中有一个术语是特色帖子。
现在我正在我的index.php
, 但是我想对每一个都进行样式化,所以我使用get_template_part
为了实现它。
当我想获得与CPT结合的特定术语的模板时,问题就来了,在本例中,是特色和视频。它适用于术语为“特色”的常规帖子,但不适用于自定义帖子类型。
这是我的代码:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
if ( get_post_type() == \'videos\' ) : ?>
<?php get_template_part( \'frontales/front\', \'video\' ); ?>
<?php elseif ( has_term( \'featured\', \'status\', $post->ID)):?>
<?php get_template_part( \'frontales/front\',\'video-featured\' ); ?>
<?php elseif ( get_post_type() == \'gallery\' ) : ?>
<?php get_template_part( \'frontales/front\', \'gallery\' ); ?>
<?php else: ?>
<?php get_template_part( \'frontales/front\', \'news\' ); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>