1

I am trying to figure out how to add my custom taxonomy for tags to the post class css when I already have added the custom taxonomy for categories. The code Im currently using to add the category taxonomy is -

  <?php $terms = get_the_terms( $post->ID, 'videoscategory' ); ?>
  <div class="box<?php foreach( $terms as $term ) echo ' ' . $term->slug; ?>">

This works fine but I also need to add a class for tags I've created with a custom taxonomy. I came across this code that will add the regular tags, but I need to use my custom tags.

<?php $tags = get_the_tags();
if( $tags ) : ?>
  <?php foreach( $tags as $tag ) { ?>
   <span class="<?php echo $tag->slug; ?>"><a href="<?php echo get_tag_link($tag->term_id); ?>"><?php echo $tag->name; ?></a></span>
  <?php } ?>
<?php endif; ?>

Thanks.

  • Does any one have an idea? – Rich Dec 23 '12 at 4:33
  • I think I found a possible solution but the problem is Im getting all the tags instead of just one that is attached to the post. – Rich Dec 23 '12 at 4:58
0

Ok I figured out how to add the terms to div's class -

In the code I have first the category, then the post type, then a custom taxonomy tag term assigned to it -

<?php $terms = get_the_terms( $post->ID, 'YOUR CUSTOM TAXONOMY CAT' ); ?>
 <?php $post_type = get_post_type($post->ID); ?>
<div class="box<?php foreach( $terms as $term ) echo ' ' . $term->slug; ?><?php echo ' '.get_post_type( $post->ID ); ?> <?php  $terms = wp_get_post_terms($post->ID,'YOUR CUSTOM TAXONOMY TAGS');  
foreach ($terms as $term) {  
    echo $term->slug;  
}  
 ?>">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.