Advertisement
alchymyth

tag list in tag archive - remove active tag

Oct 14th, 2011
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 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 remove the current tag from 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. $list = ''; $sep = '';
  17. //get the post tags
  18. $posttags = get_the_tags($post->ID);
  19.     if($posttags) :
  20.     //build new tag list
  21.         foreach( $posttags as $tag ) {         
  22.             if( $tag->slug != $this_tag ) {
  23.             $list .= $sep . '<a href="' . get_tag_link( $tag->term_id) . '">' . $tag->name . '</a>';
  24.             $sep = $separator;
  25.             }
  26.         if( !$list ) $list = ' - ';
  27.         }
  28.     $list = $before . $list . $after;
  29.     endif;
  30. endif; //end of is_tag()
  31. return $list;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement