HOW TO SHOW RELATED POST ON WORDPRESS 2
METHOD 2.
Showing Related Posts in WordPress without you using a Plugin
Did you miss the first method? Click Below
Copy and Paste the following code in single.php where you may want to display related posts
<?php
//for use in the loop, list 7 post titles related to first tag on current post $tags = wp_get_post_tags($post->ID); if ($tags) { echo 'Related Posts';
'post__not_in' => array($post->ID), $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'posts_per_page'=>7,
while ($my_query->have_posts()) : $my_query->the_post(); ?> 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) {
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php endwhile; } wp_reset_query(); }
?>
Showing Related Posts in WordPress without you using a Plugin
Did you miss the first method? Click Below
Copy and Paste the following code in single.php where you may want to display related posts
<?php
//for use in the loop, list 7 post titles related to first tag on current post $tags = wp_get_post_tags($post->ID); if ($tags) { echo 'Related Posts';
'post__not_in' => array($post->ID), $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'posts_per_page'=>7,
while ($my_query->have_posts()) : $my_query->the_post(); ?> 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) {
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php endwhile; } wp_reset_query(); }
?>
Post a Comment