Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

<a href="<?php echo get_tag_link($tag->id); ?>"><?php echo $tag->name; ?></a>

I was using this to try to list the first tag for a post, and make it so that when you click on that tag you go to a page which lists all of the posts with that tag. Instead, when you click the link it just refreshes the page. I tried going directly to one of our tag pages and it exists but it's totally empty.

How do I get each tag to link to it's tag page and how do I populate tag pages with posts?

share|improve this question
add comment

1 Answer

you haven't shown in your code how you get $tag, therefore I include my version (the code has to be in the loop):

<?php $tags = get_the_tags(); 
if( $tags ) foreach( $tags as $tag ) { ?>
<a href="<?php echo get_tag_link($tag->term_id); ?>"><?php echo $tag->name; ?></a>
<?php break; } ?>

http://codex.wordpress.org/Function_Reference/get_the_tags

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.