Show Posts of a Specific Tag Tagphp

The tag.php template functions nearly identically to the category.php template. It is invoked when a visitor requests a specific tag. This template is only beneficial if you are actively tagging the content on your site. Most likely, you are assigning categories to content, because that is a natural human organization structure, but tagging is not as clear cut, and often feels like an additional step.

Nevertheless, if you are diligent in tagging content, a tag template is a nice addition to your layouts and can be beneficial to cross-pollinate posts with related content. When this template is called, the loop automatically filled with posts of a particular tag for rendering. For a more in-depth look at how the loop actually works, refer to Chapter 5.

Likewise, you can create a template for a specific tag. The difference here is that the template filename uses the tag slug rather than the ID. If you wanted a special template for the Ponies tag, you would use the slug of the tag, to create a new template titled tag-ponies.php. You will need to verify the tag's slug on the Manage Tags Control Panel.

Using the category and tag templates may not be the way you envisioned your content being viewed, especially if you are using WordPress more as a content management system. However, simply including these templates is free functionality delivered from the WordPress core. These templates enable your visitors to explore your content in different ways and perhaps add a little stickiness to your site because your content is viewed in new and interesting ways. Categories and tags group related content and using these templates creates an organic presentation for discovery of your site.

Do not brush these off as simply reverse chronological listings of related content, like an archives page. Envision creative ways to present your data; because you have visitors who are interested in at least some of your content, why not expose them to related items?

Was this article helpful?

0 0

Post a comment