bitbadger.solutions-blog-theme/source/_posts/2007/adding-tags-to-a-wordpress-theme.md
Daniel J. Summers 67dcb2f77c Initial import
brought over all the files from the Jekyll version, fixed categories,
reformatted for different markdown processor
2017-09-02 11:49:59 -05:00

1.5 KiB

layout, title, author, date, categories, tags, summary
layout title author date categories tags summary
post Adding Tags to a WordPress Theme Daniel 2007-11-25 22:47:28
Programming
PHP
WordPress
tag
template
theme
wordpress
Now that WordPress supports tags, this is how to put them in an existing theme

WordPress 2.3 introduced tags, but unless you're using the default theme, your theme (like mine) probably didn't support them. Nowhere did I find a good example of how to add tags to your theme. Then, I was playing around with the theme switcher on my personal blog, and discovered that the default theme had tag support. I looked at it, and it was amazingly simple.

There is a new template tag called ...drumroll... the_tags. It takes three parameters: how to begin the list, how to separate each tag, and how to end the list. The tag does not do any output if a post hasn't been tagged, so it can safely sit in your theme until you need it to be active.

Here's how I did it in my personal blog.

{% codeblock lang:php %}

Tags » ', ' • ', ''); ?>

{% endcodeblock %}

Of course, you could also do it using an unordered list...

{% codeblock lang:php %}

  • ', '
  • ', '
  • '); ?>

    {% endcodeblock %}

    Drop some styling for the "tags" class in your theme's CSS, and you're good to go!

    (Well, not quite. You'll want to make sure to make the same change in your main index template, single post template, and archive template, so that the tags appear no matter how the user got to the post.)