Using get_the_tag to label post titles
-
I’m following the instructions on this page to add some HTML to my home page that labels a post title if it has one particular tag attributed to it. My code is placed in the template’s index within the loop, after the title:
<?php // get the post's tags $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { echo $tag->name . ' '; } } ?> <?php // If the post is tagged with "NSFW," add: if ($all_the_tags); $all_the_tags = get_the_tags(); foreach($all_the_tags as $this_tag) { if ($this_tag->name == "NSFW" ) { ?> <span class="nswf">[NSWF]</span> <?php } else { // if it's not, do nothing } } ?>
However, I’m getting an error on the line with
foreach($all_the_tags as $this_tag) {
that it’s an invalid argument.Any ideas?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Using get_the_tag to label post titles’ is closed to new replies.