获取当前帖子';s分类法将术语显示为id


Get the current posts's taxonomies terms to display them as an id

我有以下代码,基本上希望它在数据type="HERE"部分显示术语的slug。这是在wordpress安装之外的一个静态html页面上。

我让它将自定义帖子类型显示为列表,但无法让它显示"类别"分类法中的术语。

<?php $args = array( 'post_type' => 'case_study' ); ?>
<?php require($_SERVER['DOCUMENT_ROOT'] . '/news/wp-load.php'); query_posts($args );  if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li data-id="id-<?php the_ID(); ?>" data-type="DISPLAY TAXONOMY OF CATERGORIES TERMS HERE">
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
            <?php the_post_thumbnail('case-study-thumb'); ?>
            <?php the_title(); ?>
        </a>
    </li>
<?php endwhile; ?>
<?php else: ?>
    <li>No Case Studies found</li>
<?php endif; ?> 

如有任何帮助,我们将不胜感激!

非常感谢

您可以简单地使用get_the_category,例如:

$data_type = '';
$categories= get_the_category();
if (is_array($categories)) foreach($categories as $cat) {
  $data_type .= ', '.$cat->cat_name;
}

我在论坛上发现了一个答案,工作很有魅力!

<?php $terms = get_the_terms( $post->ID , 'categories' ); foreach( $terms as $term ) {  print $term->slug;  unset($term); }?>

其中'打印$term->slug;'是的,可以将slug更改为name以打印分类术语的名称:-)