ianb-1
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: Displaying “Related Tags” How to? Is there any plugins?Wp Recipes has a cod snippit that shows related post via tag. The original code on the page has an issue that it does close the wp_query and it will mess up your comments, if they fall after.
The original code can be found here:
http://www.wprecipes.com/how-to-show-related-posts-without-a-plugin/Below is my modified version that fixes that wp_query problem using wp_reset_query();
<?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() ) { echo '<div class="hr_bottom"></div><div id="relatedContent"><ul><h2>Related Posts</h2>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><span class="title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span> <span class="meta"> - <?php the_time('l, F j, Y G:i'); ?> - <a href="<?php the_permalink() ?>#commenting" title="Jump to the comments"><?php comments_number('0 Comments','1 Comment','% Comments'); ?></a></span></li> <?php endwhile; wp_reset_query(); } echo '</ul></div>'; } ?>Forum: Fixing WordPress
In reply to: Passing a variable to query_postsThank you both. I’ve got my issue sorted out now. I knew it was something simple like that – but it was Friday and my brain had stopped.
Viewing 2 replies - 1 through 2 (of 2 total)