Related posts
-
I’m trying to display related posts based on tags, but I’m running into a few things that just aren’t working right.
Here’s the code I’m using:
<?php global $post; $nextTagThumb='-1'; $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag) : ?> <?php if ($tags) { $what_tag = $tags[($nextTagThumb+'1')]->term_id; $args=array( 'tag__in' => array($what_tag), 'post__not_in' => array($post->ID), 'showposts'=>6, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <!--content goes here--> <?php endwhile; } wp_reset_query(); $nextTagThumb = ($nextTagThumb+1); } ?> <?php endforeach; ?>The two main problems I’m having are:
– I can’t seem to limit what category it pulls from, which I’d like to be able to do. Otherwise, if I happen to have the same tag in a different category, it connects them, which is not ideal.
– The ‘showposts’ line doesn’t seem to be working at all. I only want to show the first six related posts, but it shows all of them, no matter what number I enter.
Any help would be much appreciated.
You can see the site I’m using this on here: http://www.fiordilattegelato.com
If you navigate to any single flavor page or single news item, you’ll see where the related posts come into play.Thanks!
The topic ‘Related posts’ is closed to new replies.