1. Ana Sayfa
  2. Wordpress İpuçları

Eklentisiz Benzer Yazılar Nasıl Yapılır?

Eklentisiz Benzer Yazılar Nasıl Yapılır?
0

Wordpress ipuçları, pek çok kullanıcının işini kolaylaştırmaktadır. Ben de elimden geldiği kadarıyla sizlere Wordpress ipuçları konusunda bildiklerimi aktarmaya çalışacağım. Bunların başında ise eklentisiz benzer yazılar özelliği… Pek çok kullanıcı wordpress benzer yazılar işlevini çeşitli eklentiler kullanarak yapsa da aslında bunu sunucuyu daha az yorarak gerçekleştirmek mümkün.

Yalnızca birkaç dosyaya bazı kodlar ekleyerek siz de sitenize eklentisiz wordpress benzer yazılar özelliğini entegre edebilirsiniz. Sonunda ise style ayarlarını da yaptıktan sonra özgün bir benzer yazılar kısmına sahip olabilirsiniz.

Bu İçerikte Okuyacaklarınız :

Eklentisiz Benzer Yazılar function.php Kodları

function.php dosyasını açıp uygun bir yere aşağıdaki kodları ekleyin:

function get_thumb($postid=0, $size=’full’) {
if ($postid<1)
$postid = get_the_ID();
$thumb = get_post_meta($postid, “resim”, TRUE);
if ($thumb != null or $thumb != ”) {
echo $thumb;
}
elseif ($images = get_children(array(
‘post_parent’ => $postid,
‘post_type’ => ‘attachment’,
‘numberposts’ => ‘1’,
‘post_mime_type’ => ‘image’, )))
foreach($images as $image) {
$thumbnail=wp_get_attachment_image_src($image->ID, $size);
?>
<?php echo $thumbnail[0]; ?>
<?php }
else {
echo get_bloginfo ( ‘stylesheet_directory’ );
echo ‘/images/resim-yok.gif’;
}
}


Tabi yukarıdaki kodlar yeterli değil. Single.php dosyasına da eklenmesi gereken kodlar var :)

Eklentisiz Benzer Yazılar single.php Kodları

<div id=”sm”>

<h3 class=”basz”> İlginizi Çekebilir </h3>
<?php
$backup = $post;
$tags = wp_get_post_tags($post->ID);
$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’=>4, // 3 yazi gosterilir
‘caller_get_posts’=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>

<div class=”b”>
<div class=”cp”>

<img src=”<?php get_thumb($post->ID, ‘full’); ?>” width=”120″ height=”80″ alt=”<?php the_title(); ?>” />
<h4><a href=”<?php the_permalink() ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></h4>
</div>
</div>

<?php endwhile;
} else { ?>
<?php
$this_post = $post;
$category = get_the_category(); $category = $category[0]; $category = $category->cat_ID;
$posts = get_posts(‘numberposts=4&offset=0&orderby=post_date&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 ) : ?>

<?php function getWords($text, $limit) {
$array = explode(” “, $text, $limit +1);
if(count($array) > $limit) {
unset($array[$limit]);
}
return implode(” “, $array); }
?>
<?php foreach ( $posts as $post ) : ?>
<?php $mycontent = strip_tags($post->post_content);
$excerpt = getWords($mycontent, 15);
$a_title = $excerpt . “…”; ?>

<div class=”b”>
<div class=”cp”>

<img src=”<?php get_thumb($post->ID, ‘full’); ?>” width=”120″ height=”80″ alt=”<?php the_title(); ?>” />
<h3 class=”bz”><a href=”<?php the_permalink() ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></h3>
</div>
</div>

<?php endforeach // $posts as $post ?>

<?php endif // $posts ?>
<?php
$post = $this_post;
unset($this_post);
?>
<?php }
}
$post = $backup;
wp_reset_query();
?>
<div class=”clear”></div>

</div>

Eklentisiz Benzer Yazılar css Kodları

Style dosyasını açıp aşağıdaki kodları ekledikten sonra temanızın çerçeve büyüklüğü, rengi, şusu, busu gibi faktörleri dikkate alarak gerekli değişiklikleri yaptığınız takdirde son derece şık bir “Wordpress Benzer Yazılar” bölümüne sahip olacaksınız…

#sm .basz{font-size:13px;}
.b h3 {font-size:11px;margin:0 0 2px 3px;}
.b {float:left;overflow:hidden;margin:10px 0px 0px 0px;padding-left:10px;width:135px;}.cp {position:relative;}
.b img {height:80px;width:120px; border-style:solid; border-color:#efefef; border-width:1px; padding:1px;}
h4.bz {font-size:11px;margin:0px 0px 0px 0px;}

Yorum Yap