Show posts with same tags as current single post
-
Hi
I’m building a theme where I’d like to display thumbnails linking to posts that has the same tags as the post you are currently viewing underneath.
Say I have two categories “Cars” and “Motorcycles”, and a post tagged with “Red” and “Two-door”. When viewing that single post I’d like to display thumbnails of each and every single post tagged either “Red” or “Two-door”, wether they are in “Cars” or in “Motorcycles” or whatever.
Found this script by MichealH on WP Recipes which is nearly what I want (great script though Micheal still!), but it only fetches posts that has the first tag not posts from every tag:
<?php //for use in the loop, list 5 post titles related to first tag on current post $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'showposts'=>5, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_post_thumbnail(); ?> </a> <?php endwhile; } wp_reset_query(); } ?>
So, anyone know how to tweak that code to show posts from all tags not only the first?
Then, secondary, if anyone know how to edit the same code to work outside the loop, I’d be very grateful!
Thanks in advance!
- The topic ‘Show posts with same tags as current single post’ is closed to new replies.