berikut ini adalah tutorial tata cara bagaimana membuat Related Posts pada halaman bawah single post wordpress tanpa harus menggunakan plugins.
berikut langkah-langkanya :
- silakan buka single.php pada themes wordpress anda
- silakan anda Copy lalu PASTE kode di bawah ini pada halaman dibawah code Content
<?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);
echo “<div><h3>Related Posts</h3>”;
$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’=>5,
‘caller_get_posts’=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() )
{
echo “<ul>”;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>
<?php endwhile;
echo “</ul>”;
}
} else echo “<span>No related posts were found!</span>”;
$post = $backup; // copy it back
wp_reset_query(); // to use the original query again
echo “</div>”;
?>
- lalu save
mudah kan, selamat mencoba
Web Hosting Murah dengan fitur lengkap serta server stabil plus Domain Gratis Selamanya
Daftar, Transfer dan Perpanjang Nama Domain, baik Domain Indonesia maupun Domain Internasional dengan harga murah dilengkapi dengan fasilitas Domain Control PAnel untuk DNS Service, Privacy Protection, Domain Forwarding, Mail Forwarding dan lainnya.
