将wordpress分类术语slug作为一个类添加到术语中

时间:2016-07-20 10:56:02

标签: wordpress custom-taxonomy

我有以下问题。对于我正在研究的项目,我使用get_the_term_list来回显特定帖子和分类中的所有术语。不,我需要能够设计出以不同方式回应的每个术语。为了实现这个目的,我想将term-> slug作为一个类添加到列表项中,但我无法使其工作。我知道如何将slug添加到ul但这不是我需要的因为那时我无法根据他们的slug设置单个列表项的样式。

所以在这一点上我使用它来获得基于当前帖子的所有条款:



<?php echo get_the_term_list( $post->ID, 'thema',  '<ul class="project-themes no-bullet"><li>', '</li><li>', '</li></ul>'  ); ?>
&#13;
&#13;
&#13;

是否有人知道如何将这些条款作为一个类的一部分。所以我得到这样的东西:

&#13;
&#13;
<?php echo get_the_term_list( $post->ID, 'thema',  '<ul class="project-themes no-bullet"><li class="term->slug">', '</li><li class="term->slug">', '</li></ul>'  ); ?>
&#13;
&#13;
&#13;

希望有人能帮助我。

2 个答案:

答案 0 :(得分:1)

这里&#39; get_the_term_list&#39;会很棘手。相反,你可以尝试这个---

  $terms = get_the_terms( $post->ID, 'your-taxonomy' );

  foreach($terms as $term){
  echo $term->slug;
  }

答案 1 :(得分:0)

修复了它对@Mickey的简单但有效的解决方案。结束这个让它像我想要的那样工作:

<?php $terms = get_the_terms( $post->ID, 'thema' ); ?>

<ul class="project-themes no-bullet">
    <?php foreach($terms as $term) { ?>
        <li class="<?php get_term_link( $term->slug); ?>">
            <a href="<?php echo get_term_link( $term->term_id ); ?>"><?php  echo $term->slug; ?></a>
        </li>
    <?php } ?>
</ul>
再次

Thanx

相关问题