views:

18

answers:

1

I have a custom taxonomy that needs a different colour applied to each term inside. I figured I could grab the slug of the taxonomy and put it in a class. Unfortunately I've been defeated with every try. I've tried a few things with get terms to no avail.

Sample of what I'd like

<div class="<?php echo $myCustomClass; ?>">the custom taxonomy</div>
A: 

First you would need to get the custom taxomomy and loop through every term applying the slug of the term as the class.

<?php
  // get the tags from your custom taxonomy, in this case it's 'skills'
  $tags = get_terms('skills');

  // print out the start of the list, putting an ID on it to make styling it easier
  echo '<ul id="taxonomy-list-skills">';
  // loop through each tag as a list item
  foreach($tags as $tag)
  {
     echo '<li class="'.$tag->slug.'">'.$tag->name.'</li>';
  }
  // close the list
  echo  '</ul>';
?> 
Paul Sheldrake
yeah that would give me a list but for what I'm needing I need it to just add the class to a term. Each post has one item only. I ended up modifying post_class() and going through that for the CSS.
curtismchale