Simple Tagging: Tags of the Current Post
Use
<?php STP_PostTags(); ?>
in any template file within the WordPress Loop to display the tags related to the current post; it will output a list of comma-separated tags:
Clicking on a tag link displays a list of the posts within that tag; displayed using the tag.php template file, if one is present (index.php will be used if tag.php is absent.).
By the way, the function STP_GetPostTags()
is the non-echoing version (returns tags as string).
Options
You can change the appearance and behaviour by modifying the plugin’s options under WP Administration > Tags > Tag Options.
When you have opened the options, scroll down to Display Tags of the Current Post.
Individual Options
You also can override the plugin’s options by using the following optional parameters in the template tag STP_PostTags()
:
STP_GetPostTags($linkformat, $include_cats, $tagseparator, $notagstext)
- $linkformat:
A string, e.g.<a href="%fulltaglink%" title="Search site for %tagname%" rel="tag">%tagname%</a>
You can use any text you like and the function will automatically replace the following identifiers:- %tagname%: name of the tag, e.g.
Coffee and Tea
- %fulltaglink%: full link, e.g.
http://site.com/tag/Coffee_and_Tea
- %taglink%: link, e.g. Coffee+and+Tea. Can be used to create links e.g. to Technorati
- %flickr%: link for Flickr compatibility, e.g.
coffeeandtea
- %delicious%: link for de.icio.us compatibility, e.g.
CoffeeandTea
- %tagname%: name of the tag, e.g.
- $include_cats:
Set to TRUE if you want post categories to be included in this list (the default is FALSE) - $tagseparator:
Tag separator string, default is', '
. - $notagstext:
Text to display if no tags found.
Examples 1: Display Flickr Tags
Here we want to provide the visitors a section „Flickr Tags“. We add the following code to our template — and as always within the WordPress Loop:
<?php STP_PostTags('<a href="http://www.flickr.com/photos/tags/%flickr%/" title="Flickr: Photos tagged with %tagname%" rel="tag">%tagname%</a>'); ?>
Examples 2: Display del.icio.us Tags
Quite similar to Flickr Tags do we display del.icio.us tags with the following code:
<?php STP_PostTags('<a href="http://del.icio.us/tag/%delicious%" title="Pages tagged with "%tagname%" on del.icio.us" rel="tag">%tagname%</a>'); ?>
Examples 3: Display Technorati Tags
Here we wanna display tags that link to Technorati:
<?php STP_PostTags('<a href="http://www.technorati.com/tag/%taglink%" title="Technorati tag search for %tagname%" rel="tag">%tagname%</a>'); ?>