* echo(ctl_get_tag_link(1)); // => http://example.org/tag/example/ * echo(ctl_get_tag_link(1, 'http://www.technorati.com/tag/%tag%')); // => http://www.technorati.com/tag/example * * * @param int $tag_id The ID of the tag to link. * @param string $taglink A custom link to use to link the tag. Must include '%tag%'. (If not set or empty, which is the default, the default Wordpress-taglink-function is used.) * @return mixed Either the link to the tag, or a Wordpress-error-code. */ function ctl_get_tag_link( $tag_id, $taglink = '' ) { $tag = &get_term($tag_id, 'post_tag'); if ( is_wp_error( $tag ) ) return $tag; $slug = $tag->slug; if ( empty($taglink) ) { $taglink = get_tag_link($tag_id); } else { $taglink = str_replace('%tag%', $slug, $taglink); } return apply_filters('tag_link', $taglink, $tag_id); } /** * Returns a list of tags of the current post. * * This function is most likely required to be run in the_loop(), * because else Wordpress most likely will not be able to extract any * tag-information at this point. * * Example: * * echo(ctl_get_the_tag_list('Tags: ', ', ', '.', true, 'http://www.technorati.com/tag/%tag%')); * * * @param string $before String to prepend to the taglist; Empty by default. * @param string $sep String to separate tags by; Empty by default. * @param string $after String to append after the tag-list is finished; Empty by default. * @param bool $link_tag Whether or not to link tags; Defaults to true. * @param string $taglink A custom link to use to link the tag. Must include '%tag%'. (If not set or empty, which is the default, the default Wordpress-taglink-function is used.) * @return mixed Either the list of tags, false if there are no tags, or a Wordpress-error code. */ function ctl_get_the_tag_list( $before = '', $sep = '', $after = '', $link_tag = true, $taglink = '' ) { $tags = get_the_tags(); if ( empty( $tags ) ) return false; $tag_list = $before; foreach ( $tags as $tag ) { if ( true === $link_tag ) { if ( empty($taglink) ) { $link = get_tag_link($tag->term_id); } else { $link = ctl_get_tag_link($tag->term_id, $taglink); } if ( is_wp_error( $link ) ) return $link; $tag_links[] = ''; } else { $tag_links[] = $tag->name; } } $tag_links = join( $sep, $tag_links ); $tag_links = apply_filters( 'the_tags', $tag_links ); $tag_list .= $tag_links; $tag_list .= $after; return $tag_list; } /** * Prints a list of tags of the current post. * * This function is most likely required to be run in the_loop(), * because else Wordpress most likely will not be able to extract any * tag-information at this point. * * Examples: * * ctl_the_tags(); * ctl_the_tags('', false); * ctl_the_tags('Tags: ', ', ', '.', true, 'http://www.technorati.com/tag/%tag%'); * * * @param string $before String to prepend to the taglist; Empty by default. * @param string $sep String to separate tags by; Empty by default. * @param string $after String to append after the tag-list is finished; Empty by default. * @param bool $link_tag Whether or not to link tags; Defaults to true. * @param string $taglink A custom link to use to link the tag. Must include '%tag%'. (If not set or empty, which is the default, the default Wordpress-taglink-function is used.) * @return mixed Either the list of tags, false if there are no tags, or a Wordpress-error code. */ function ctl_the_tags( $before = 'Tags: ', $sep = ', ', $after = '', $link_tag = true, $taglink = '' ) { $return = ctl_get_the_tag_list($before, $sep, $after, $link_tag, $taglink); if ( is_wp_error( $return ) ) return false; else echo $return; } ?>