• Merhaba Ziyaretçi.
    "Yapay Zeka Objektif " Fotoğraf Yarışması başladı. İlgili konuya  BURADAN  ulaşabilirsiniz. Sizi de bu yarışmada görmek isteriz...

Eklenti Olmadan Benzer Konular Kodu

YoRuMSuZ

Biz işimize bakalım...
Wordpress benzer konuları (related post) çağıran pluginler mevcut. Ancak bazı site sahipleri asgari düzeyde eklenti kullanmak taraftarı oldukları için sistemin işleyişi kodlarla halletmeyi seviyor.

Aşağıdaki iki farklı kod eklenti kullanmadan wordpress sitenizde benzer konuları listeliyor.

1. Kod: Etikete göre benzer konular.
Kod içerisinde renkli kısımlar kaç adet benzer konunun listeleneğini gösteriyor.
Kod:
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
	$tag_ids = array();
	foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;

	$args=array(
		'tag__in' => $tag_ids,
		'post__not_in' => array($post->ID),
		'showposts'=>[COLOR="red"]10[/COLOR],
		'caller_get_posts'=>1
	);
	$my_query = new wp_query($args);
	if( $my_query->have_posts() ) {
		echo '<h3>Benzer Konular - Etiket</h3><ul>';
		while ($my_query->have_posts()) {
			$my_query->the_post();
		?>
			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
		<?php
		}
		echo '</ul>';
	}
}
?>

2. Kod: Konu başlığına göre benzer konular.
Kod:
<?php
    $this_post = $post;
    $category = get_the_category(); $category = $category[0]; $category = $category->cat_ID;
    $posts = get_posts('numberposts=6&offset=0&orderby=post_date&order=DESC&category='.$category);
    $count = 0;
    foreach ( $posts as $post ) {
    if ( $post->ID == $this_post->ID || $count == [COLOR="red"]10[/COLOR]) {
    unset($posts[$count]);
    }else{
    $count ++;
    }
    }
    ?>
 
    <?php if ( $posts ) : ?>

    <h3>Benzer Konular- Konu</h3>
    <ul>
    <?php foreach ( $posts as $post ) : ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> </li>
    <?php endforeach // $posts as $post ?>
    </ul>

    <?php endif // $posts ?>
    <?php
    $post = $this_post;
    unset($this_post);
    ?>
 
Top