1
votes

I have the following question. For a project i am working on i am using get_the_term_list to echo all terms from a particular post and taxonomy. No i need to be able to style every term that gets echoed out a different way. For this to work i would like to add the term->slug as a class to the list item, but im not able to make this work. I know how to add the slugs to the ul but thats not what i need because then i am not able to style the individual list items based on their slug.

so at this point i am using this to get all the terms based on the current post:

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

Does someone have a clue how to get the slug of the terms as a class on the li. So i get something like this:

<?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>'  ); ?>

Hope someone can help me with this.

2

2 Answers

1
votes

Here 'get_the_term_list' will be tricky. Instead, you can try this ---

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

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

Fixed it thanx to @Mickey for his simple but effective solution. Ended up with this to get it working like i wanted:

<?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 again