Salı, Ocak 16, 2018

WordPress Rastgele Resimli Yazı Çekme





Wordpress'te hiç bir eklenti kurmadan Rastgele Yazıları Resimleriyle birlikte çekmek istermisiniz o zaman tam yerine geldiniz. Öncelikle kullandığımız temanın functions.php dosyasını açarak aşağıdaki kodu ekleyelim.


add_theme_support (‘post-thumbnails’);
Daha Sonra Aşağıdaki Kodu Kullanabilirsiniz...
<?php query_posts($query_string . 'orderby=rand&&showposts=10'); ?> 
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php if(has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?>
<a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'>
<img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='122px' height='80px' /></a>
 
<a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
 
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Not: showposts=10 yazan yerdeki rakamı kaç tane yazı göstermek isterseniz onunla değiştirebilirsiniz.

Hiç yorum yok:

Yorum Gönder

Teşekkürler...Yorumunuz Onaylandıktan Sonra Yayınlanacaktır...