I'm trying to call a list of tags for each post in a get_post query outside the loop.
I can get it to return all the tags but not the links. I am using this code..
<ul class="tagslist">
<?php
global $post;
foreach(get_the_tags($post->ID) as $tag) {
echo "<li><a href=\"<?php echo get_tag_link($tag_id); ?>\">$tag->name</a></li>";
}
?>
</ul>
But all I get is <a href="<?php echo get_tag_link(0); ?>">Tag</a> :(
Does anyone know how I can solve this?
Thanks
Might need to add:
global $wp_query;
$wp_query->in_the_loop = true;
Edit - fixed it with this :)
echo '<li><a href="http://www.mysite.co.uk/tag/'.$tag->slug.'" rel="tag">'.$tag->name.'</a></li>';
to make..
<?php
global $post;
foreach(get_the_tags($post->ID) as $tag) {
echo '<li><a href="http://www.mysite.co.uk/tag/'.$tag->slug.'" rel="tag">'.$tag->name.'</a></li>';
}
?>
Didn't try the other
mrwangkai
Member
Posted 3 years ago #
@boon_ what if you have multiple tags. You solution works great, but I'm not sure how I can limit it to a single tag.