How do I use is_tag on a post in WordPress's archive.php
I want to be able to add a particular thing to everyone post on my blog based on that posts tags.
On my category pages especially. So I'm in my archive.php file and I want to use if (is_tag()
) to print some stuff based on if the tag is there.
The prob开发者_运维百科lem is of course that its not working. I'm assuming its because I can't use the is_tag
on non tag pages?
is_tag
tells you whether the page being viewed is a tag archive page (a page that lists posts by tag). It is not a function to retrieve the tags for a post. Use get_the_tags
for that.
The proper usage is has_tag
.
<?php if (has_tag()) { ?>
tags available
<?php } else { ?>
no tags
<?php } ?>
精彩评论