开发者

Custom taxonomy as HTML class

I ha开发者_运维知识库ve 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>


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜