Pasang Related Post By Category Tanpa Plugin

Untuk membuat related post wordpress tanpa plugin berikut cara dan langkah-langkahnya:
cari kode <?php the_content(); ?> pada single.php dan tempatkan kode berikut dibawah kode tadi

<?php
$this_post = $post;
$category = get_the_category(); $category = $category[0]; $category = $category->cat_ID;
$posts = get_posts(‘numberposts=10&offset=0&orderby=post_date&order=DESC&category=’.$category);
$count = 0;
foreach ( $posts as $post ) {
if ( $post->ID == $this_post->ID || $count == 10) {
unset($posts[$count]);
}else{
$count ++;
}
}
?>
<?php if ( $posts ) : ?>
<div>
<h2>Related Posts</h2>
<ul>
<?php foreach ( $posts as $post ) : ?>
<li><a href=”<?php the_permalink() ?>” title=”<?php echo trim(str_replace(“n”,” “,preg_replace(‘#<[^>]*?>#si’,”,get_the_excerpt()))) ?>”><?php if ( get_the_title() ){ the_title(); }else{ echo “Untitled”; } ?></a> (<?php the_time(‘F jS, Y’) ?>)</li>
<?php endforeach // $posts as $post ?>
</ul>
</div>
<?php endif // $posts ?>
<?php
$post = $this_post;
unset($this_post);
?>

Save dan Selesai!! semoga cara membuat Related Post By Category Tanpa Plugin ini berguna.

4 Responses to Pasang Related Post By Category Tanpa Plugin

  1. Salam kenal … saya sudah mencobanya, tapi tidak berhasil … dimana salahnya ya..

    • jangan menyerah dan diulang sekali lagi !!
      coba anda cari kode <?php the_content(); ?> pada /public_html/wp-content/themes/nama_tema_anda/single.php kemudian anda copy kode yang panjang diatas dibawah kode <?php the_content(); ?>

  2. bisa mas,makasih ya,,
    tp jadinya by: category: …. gitu mas.
    kalo misalnya nama site kita aja tp ga bisa di link bisa ga mas?

  3. thanks atas infonya berguna bgt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s