2

我有以下代码,基本上希望它在 data-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; ?> 

任何帮助将不胜感激!

非常感谢

4

2 回答 2

1

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

$data_type = '';
$categories= get_the_category();
if (is_array($categories)) foreach($categories as $cat) {
  $data_type .= ', '.$cat->cat_name;
}
于 2012-09-05T12:10:21.243 回答
1

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

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

'print $term->slug;' 也就是说,slug 可以更改为 name 以打印分类术语的名称:-)

于 2012-09-05T12:18:00.093 回答