Sharing Knowledge is the Best


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

Tag Cloud

%d bloggers like this: