Advertisement
alchymyth

tag list in tag archive

Oct 14th, 2011
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. add_filter('the_tags','the_tags_in_tag_archive');
  2. /*filter to replicate 'the_tags()' in a tag archive, to un-link the current tag in the list
  3. * alchymyth 2011
  4. */
  5. function the_tags_in_tag_archive($list) {
  6. if( is_tag() ) : //do the following only in tag archives
  7. global $post;
  8. $this_tag = get_query_var('tag');
  9. //retrieve the $before,$sep,$after variables from the list
  10. $before = explode('<a href', $list);
  11. $before = $before[0];
  12. $afters = explode('</a>', $list);
  13. $after = array_pop($afters);
  14. $separator = explode('<a href', $afters[1]);
  15. $separator = $separator[0];
  16. $sep = '';
  17. //get the post tags
  18. $posttags = get_the_tags($post->ID);
  19.     if($posttags) :
  20.     //build new tag list
  21.     $list = $before;
  22.         foreach( $posttags as $tag ) {
  23.             $list .= $sep;
  24.             if( $tag->slug != $this_tag ) $list .= '<a href="' . get_tag_link( $tag->term_id) . '">';
  25.             $list .= $tag->name;
  26.             if( $tag->slug != $this_tag ) $list .= '</a>';
  27.             $sep = $separator;
  28.         }
  29.     $list .= $after;
  30.     endif;
  31. endif; //end of is_tag()
  32. return $list;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement