Bileşen etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Bileşen etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

20 Şubat 2017 Pazartesi

WordPress Sizin için Seçtiklerimiz Bileşeni

WordPress için kodlanmış özel sizin için seçtiklerimiz bileşeni eklentisiz.

Tema İşlevleri (functions.php) ?> kodundan 1 satır önce Shift+Enter yaparak 1 satır alta inip ekleyiniz. Önemli not functions dosyasında asla boş satır olmamalı, bunun için sürekli düzenleme yapmadan önce yedek alınız.

Ön izleme resim



[php]/** yazi kes yan menu sizin icin sectiklerimiz basladi**/
add_theme_support( 'post-thumbnails' );
function yazikes($text, $limit = 25, $ending = '...') {
if ($limit < strlen( $text )) {
$text = str_replace( '[...]', '', $text );
$text = substr( $text, 0, $limit );

$text = substr( $text, 0, 0 - strlen( strrchr( $text, ' ' ) ) );

$text = $text = $text . $ending;

preg_replace( '/\[caption.*\[\/caption\]/', '', $text );
$text = strip_tags( $text );
}

return $text;
}
/** yazi kes yan menu sizin icin sectiklerimiz bitti**/[/php]

Kenar çubuğu (sidebar.php) dosyasına endwhile; div'den önce ekleyiniz.

[php]<h3>Sizin için Seçtiklerimiz</h3>

<?php
global $post;
$args = array( 'numberposts' => 4, 'orderby' => 'rand' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php $id =$post->ID;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$pattern = '!<img.*?src="(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0];?>
<div class="spotnews">
<a href="<?php the_permalink(); ?>">
<?php
$default = get_bloginfo('template_url');
$cdn22= "/images/onizleme.png";
if ($image_src != '')
echo '<img src="'.$image_src.'" alt="" width="100px" height="100px"/>';
else
echo '<img src="'.$default.''.$cdn22.'" alt="" width="100px" height="100px"/>';
?> </a>
<a href="<?php the_permalink(); ?>">
<h1><?php the_title(); ?></h1>
</a>
<a style="font-weight:normal; color:#000000" href="<?php the_permalink(); ?>">
<?php echo yazikes($post->post_content,120); ?><br/>
</a>
</div>
<div class="dlt"></div>
<?php endforeach; wp_reset_query(); ?>[/php]

Kaç adet konu göstereceğini yukarda verilen kod kısmından $args = array( 'numberposts' => 4 kısmından arttırıp veya düşürebilirsiniz.

Aşağıdaki ön izleme resmini tema klasörü images içine atınız, öne çıkan görsel kullanmazsanız otomatik gösterilecektir.
Yolu >> "/images/onizleme.png"


Style.CSS dosyanın en altına ekleyniz,

/** sizin icin sectiklerimiz basladi **/
.spotnews {line-height:16px; color:#000000; height:110px; border-bottom:1px dotted #666666; margin-bottom:10px; overflow:hidden;}
.spotnews h1, .spotnews h1 a {margin-bottom:2px; font-size:14px; font-weight:bold; color:#094386; line-height:20px;}
.spotnews img{float:left; margin:0px 5px 5px 0px; border:1px solid #666666; padding:2px;}
.dlt {clear:both;}
/** sizin icin sectiklerimiz bitti **/