WordPress

WordPress Yazı Çekme Kodları

WordPress tema kodlarken aşağıdaki yazı çekme kodlarını sürekli kullananlar için bir liste hazırladım.

Buğra Yazar

2 yıl önce

WordPress Yazı Çekme Kodları

WordPress tema kodlarken aşağıdaki yazı çekme kodlarını sıkça kullananlar için bir liste hazırladım. Elimden geldiğince bu listeyi güncel tutmaya çalışacağım. Tema kodlarken lazım olacak wp kodlarını WordPress Kod Arşivi bölümü inceleyebilirsiniz.

Siteniz kod eklemeyi bilmiyorsanız WordPress Siteye Kod Nasıl Eklenir? yazısını tıklayarak hemen öğrenebilirsiniz.

Normal yazı çekme

<?php if ( have_posts() ) : ?>
	<?php while ( have_posts() ) : the_post(); ?>
	Yazı başlığını gösterir: <?php the_title(); ?>
        Yazı linkini gösterir: <?php the_permalink() ?>
        Yazı özetini gösterir: <?php the_excerpt(); ?>
        Yazı içeriği gösterir: <?php the_content(); ?>
	<?php endwhile; ?>
<?php endif; ?>

Kategoriye Göre Yazı Çekme

cat=1 yazan yere kategorinizin ID adresini yazabilirsiniz.
showposts: Kaç adet yazı gösterileceğini belirler, bu sayıyı değiştirebilirsiniz.

<?php $CatPosts = new WP_Query("cat=1&showposts=5"); while($CatPosts->have_posts()) : $CatPosts->the_post();?>
        Yazı başlığını gösterir: <?php the_title(); ?>
        Yazı linkini gösterir: <?php the_permalink() ?>
        Yazı özetini gösterir: <?php the_excerpt(); ?>
        Yazı içeriği gösterir: <?php the_content(); ?>
<?php endwhile; ?>

Rastgele Yazı Çekme Kodu

orderby=rand = random olarak yazıları çekmek için kullanılan parametredir
showposts: Kaç adet yazı gösterileceğini belirler, bu sayıyı değiştirebilirsiniz.

<?php query_posts($query_string . 'orderby=rand&&showposts=5'); ?>
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
        Yazı başlığını gösterir: <?php the_title(); ?>
        Yazı linkini gösterir: <?php the_permalink() ?>
        Yazı özetini gösterir: <?php the_excerpt(); ?>
        Yazı içeriği gösterir: <?php the_content(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

Rastgele Resimli Yazı Çekme Kodu

<?php query_posts($query_string . 'orderby=rand&&showposts=5'); ?>
<?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; ?>

Bunlar ilginizi çekebilir