我有一个关于CPT UI的问题,我想展示一下文章的类别,
<?php
$args= array(\'post_type\'=>\'formation\', \'orderby\'=>\'date\', \'order\'=> \'DESC\', \'posts_per_page\' => 9);
$loop= new WP_Query($args);$i=0;
if ( $loop-> have_posts() ) : while ( $loop-> have_posts() ) : $loop-> the_post();
?>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'full\' ); ?>
<div class="news-container">
<div class="img-news" style="background-image: url(\'<?php echo $thumb[\'0\'];?>\')">
<div class="filtre-news"></div>
</div>
<h3><?php the_title(); ?></h3>
</div>
<?php endwhile; endif; ?>
我的自定义帖子类型名称是:formation,taxomonie是promo。。
谢谢大家
SO网友:dbeja
您可以使用get_the_terms 检索每个帖子的特定分类的术语。您可以在循环中使用此选项:
$terms = get_the_terms( get_the_ID(), \'promo\' );
foreach ( $terms as $term ) {
echo $term->name;
}
get\\u the\\u terms返回一个术语数组,每个术语都具有以下属性:
WP_Term Object
(
[term_id] =>
[name] =>
[slug] =>
[term_group] =>
[term_taxonomy_id] =>
[taxonomy] =>
[description] =>
[parent] =>
[count] =>
[filter] =>
)