Get Current Post Tags (Without Link to Tag Page)
I’ve quickly figured it out.
I had to clean the contents of $tagdisplay before the loop rotates for the second post, because the contents of the variable were prepended to the tags of current post.
A better example:
You have posts named 1, 2, 3, 4 and 5.
Each post has 1 tag: tag1, tag2, tag3, tag4, tag5.
The loop runs for post 1 and displays tag1, the value of tag1 is inserted into $tagdisplay.
The loop runs for post 2, but the above code caused it to display the value of $tagdisplay and then display any other tags, associated with the current post, causing an output: tag1, tag2.
So the fix is easy as inserting this above the code in the first post:
$tagdisplay=''; unset($tagdisplay); // failsafe
I’m trying to do this for http://www.coloringpagesite.com my coloring page site but I dont understand…what is the “loop”?
Since no one who would actually know is answering..I think it has something to do with placing the code inside the php brackets, rather than outside. Although I’m not sure if it only applies to functions.php, I think so.
Thanks for your solution! This worked perfectly for me.
esmi’s link has more info for a complete understanding but the loop is the area of your code that looks for posts and then performs the same action on the ones that it finds (usually spitting out the title and content of the post into the code).
So, for instance, after
<?php if ( have_posts() ) : ?> <?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?> <?php endif; ?>
is that correct?
<?php else : ?>
does it have to close with an end?
What is the difference when you put code inside
<?php(existing code here); (new code here); ?>
<?php(existing codes here); ?> <?php (new code here); ?>
no difference in the result;
maybe minute difference in the procesing speed – i would assume the first one is faster.
- The topic ‘Get Current Post Tags (Without Link to Tag Page)’ is closed to new replies.