WordPress related articles (non-plugin) implementation method

WordPress related articles (non-plugin) implementation method

Adding related articles after each log can achieve in-depth reading of related articles. The plug-in method is simple, but it seems cumbersome. The following is implemented with code:

<div class="related_posts"> <?php
$backup = $post;
$tags = wp_get_post_tags($post->ID);
$tagIDs = array();
if ($tags && count($tags)>1) {
echo '<h3>Related logs</h3>';
echo '<ul class="ul_style">';
$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'=>8,
'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><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>” target=”_blank”> <?php the_title(); ?> </a></li>
<?php endwhile;echo '</ul>';} else { ?> <?php }} $post = $backup;wp_reset_query();?> </div>

Just add it at the end of single.php article.

<<:  $40/year/1024M memory/80G space/3TB traffic VPS —— BudgetVM

>>:  Godaddy Economy Web Hosting $1/month

Recommend

HETNiX: Black Friday discounts, dedicated servers, VPS, etc.

HETNiX has its own computer room. Black Friday de...

Clouvider E3-1270v5 16GB RAM SSD Hard Drive Dedicated Server Review

Details: Clouvider: UK dedicated server discount,...

VP Easy: $14.4/year/1GB/15GB SSD/1TB traffic/1 IP/KVM/Las Vegas

VP Easy is a new hosting provider, but it is owne...

Neosurge: $6.95/month/128M memory/5G space/200G traffic/Xen

Introduction NeoSurge is an American hosting comp...

Falcons: $1.18/month/512MB RAM/6GB SSD space/unlimited traffic/1Gbps/KVM/UK OVH

Falcons, which should be a newly established UK m...

OLVPS: 28 yuan/month/1GB memory/10GB SSD space/1TB traffic/100Mbps/KVM/Portland

OLVPS, also known as t667, has a nice boss and hi...

inbox.eu: Domain mailbox, 100GB space, 9.99 euros per user per year

inbox.eu, can be used for domain name mailboxes, ...

DeepNet Solutions 512MB RAM KVM VPS Los Angeles Review

Details: DeepNet Solutions: $0.9/year/64MB memory...

SolusVM series: some tips on using SolusVM

1. Forced deletion of Node php /usr/local/solusvm...