SHARE
TWEET

all tags for a category in a linked list

alchymyth Apr 14th, 2011 158 Never
  1. <?php
  2.         query_posts('category_name=work');
  3.         if (have_posts()) : while (have_posts()) : the_post();
  4.         $posttags = get_the_tags();
  5.                 if ($posttags) {
  6.                         foreach($posttags as $tag) {
  7.                                 $all_tags_arr[] = $tag->term_id; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
  8.                         }
  9.                 }
  10.         endwhile; endif; wp_reset_query();
  11.  
  12.         $tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
  13.         //echo '<pre>'.print_r($tags_arr, true).'</pre>'; //OUTPUT FINAL TAGS FROM CATEGORY
  14.  
  15. echo '<ul>';
  16. foreach ($tags_arr as $tag) {
  17. echo '<li><a href="' . get_tag_link($tag) . '">' . get_tag($tag)->name . '</a></li>';
  18. }
  19. echo '</ul>';
  20.  
  21. ?>
RAW Paste Data
Top