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.

I'm having problems getting all related posts of the current viewing tag. Does anyone know how you can do this dynamic? I want to create a own kind of 'archive' page for this.

share|improve this question
add comment

3 Answers

Ok .. after searching for a while I figured out what I was doing wrong. I wasn't including custom post types in the loop. I ended up constantly with 'not found'.

Whats the solution:

query_posts( array( 'post_type' => 'blog', 'showposts' => 3, 'orderby' => 'rand') );  if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

And it queues all posts with the current viewing tag!

Special thanks to Sven and Kaiser!

share|improve this answer
add comment

Simply use a tag archive for that.

You can grab a term/taxon, then display a link to its archive using get_tag_link().

As you can see from the Template Hierarchy Diagram, there're the following tempalte names, that will trigger (in hierarchical & parent/child theme) order:

  • tag-{$slug}.php
  • tag-{$id}.php
  • tag.php
  • archive.php

There you will have - depending on your URl/Route - the posts available and can proceed them using a plain loop, like the one you can see in the codex. All filters are available, as well as well as all filters like pre_get_posts, etc. and Conditional Tags like is_tag() that will determine if you're on a tag archive.

share|improve this answer
add comment

You can use the default get_posts() function from WordPress with taxonomy parameter.

share|improve this answer
    
Thanks Sven, but how do I get the posts related to the current tag? I've managed to output the single_tag_title(); but don't know how to get the rest.. –  rwzdoorn Dec 11 '12 at 10:31
    
So, you need the tag of the current post? You can get the tags with the function get_the_tags() (codex.wordpress.org/Function_Reference/get_the_tags) –  Sven Dec 11 '12 at 10:34
1  
Nope sven, This is what I did: When viewing a post, I click on one of the tags (like Android), i'm going to the tag.php page and want to display all related posts with the tag 'Android'.. –  rwzdoorn Dec 11 '12 at 10:43
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.