Powered by Blogger.

Sunday 7 April 2013

Wordpress : Membuat Related Post Berdasarkan Kategori

Posted by on Sunday 7 April 2013
Membuat Related Post Berdasarkan Kategori - Lama tidak update postingan, kebetulan lagi bikin theme sekalian aja deh share tutorial wordpress untuk bikin related post by kategori. Gampang dan sangat muda untuk bikin related post. Berikut stepnya :


  • Pertama silahkan buka single.php
  • Kemudian cari bagian ini <?php comments_template(); ?> (gunakan CTRL+F)
  • Kemudian Pastekan kode berikut 

<?php
$this_post = $post;
$category = get_the_category(); $category = $category[0]; $category = $category->cat_ID;
$posts = get_posts('numberposts=6&offset=0&orderby=post_dat e&order=DESC&category='.$category);
$count = 0;
foreach ( $posts as $post ) {
if ( $post->ID == $this_post->ID || $count == 5) {
unset($posts[$count]);
}else{
$count ++;
}
}
?>

<?php if ( $posts ) : ?>
<ul>
<?php foreach ( $posts as $post ) : ?>
<li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ){ the_title(); }else{ echo "Untitled"; } ?></a> (<?php the_time('F jS, Y') ?>)</li>
<?php endforeach // $posts as $post ?>
</ul>
<?php endif // $posts ?>
<?php
$post = $this_post;
unset($this_post);
?>

  •  Udah sekarang save pekerjaan anda tinggal penyesuaian CSSnya.
Ok sekian dulu tentang Membuat Related Post Berdasarkan Kategori nanti kita lanjut tutorial wordpress berikutnya. 
close