Advertisement
alchymyth

cat tag link

Jun 17th, 2011
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. if( is_category() ) :
  3. $cat_id = get_query_var('cat');
  4. query_posts('posts_per_page=-1&cat='.$cat_id);
  5.  if (have_posts()) :
  6.  $posttags = array(); $the_tags = array();
  7.  while (have_posts()) : the_post();
  8.    $tags = get_the_tags($post->ID);
  9.    if( $tags ){
  10.      foreach( $tags as $tag ) {
  11.      $posttags[] = $tag->term_id;
  12.      };
  13.    }
  14.  endwhile;
  15. $slug = get_category($cat_id)->slug;
  16.  $posttags = array_unique( $posttags );
  17.    foreach( $posttags as $tag ) {
  18.    $tag = get_tag($tag);
  19.    $the_tags[] = '<a href ="' . get_bloginfo('wpurl') . '/?category_name=' . $slug . '&tag=' . $tag->slug . '">' . $tag->name . '</a>';
  20.    }
  21.  sort($the_tags); //sort optional
  22.    if( $the_tags ) {
  23.    echo '<ul><li>' . implode("</li>\n<li>", $the_tags) . '</li></ul>';
  24.    }
  25.  endif; wp_reset_query();
  26. endif;
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement