Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Does any one have an idea? –  mygm26 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. –  mygm26 Dec 23 '12 at 4:58
add comment

1 Answer

up vote 0 down vote accepted

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;  
}  
 ?>">
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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