Related Posts by Tag – View all posts
-
I need help! I’m using the below code to generate a list of related posts by tags. I currently have it set to show the latest 4 posts.. but how to i generate a “view all” link to show the remaining posts that have the same related tag?
<?php //for use in the loop, list 5 post titles related to first tag on current post $backup = $post; // backup the current object $tags = wp_get_post_tags($post->ID); $tagIDs = array(); if ($tags) { $tagcount = count($tags); for ($i = 0; $i < $tagcount; $i++) { $tagIDs[$i] = $tags[$i]->term_id; } $args=array( 'tag__in' => $tagIDs, 'post__not_in' => array($post->ID), 'showposts'=>4, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><span><?php the_date() ?></span><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> <?php endwhile; } else { ?> <p>No related posts found!</p2> <?php } } $post = $backup; // copy it back wp_reset_query(); // to use the original query again ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Related Posts by Tag – View all posts’ is closed to new replies.