Display Related Posts in WordPress without a Plugin
Paste the following code in single.php where you want to display related posts
03 | $tags = wp_get_post_tags($post->ID); |
06 | $first_tag = $tags[0]->term_id; |
08 | 'tag__in' => array($first_tag), |
09 | 'post__not_in' => array($post->ID), |
13 | $my_query = new WP_Query($args); |
14 | if( $my_query->have_posts() ) { |
15 | while ($my_query->have_posts()) : $my_query->the_post(); ?> |
16 | <a href="<?php the_permalink() ?>" rel="bookmark"title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> |
留言
張貼留言