Wordpress kenar çubuğu / widget yeni mesajlar ile görüntüleri göstermek için sorgula

1 Cevap php

Ben bu kodu kullanıyorum bir widget bir Wordpress kategoriden yeni öğeleri göstermek için ...

<ul>
<?php $recent = new WP_Query("cat=1231&showposts=5"); while($recent->have_posts()) : 
$recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
</ul>

... Ama nasıl bu sorgu her yazının içinde ilk görüntüyü görüntülemek ve durumda görüntü yok bir 'standart' görüntüsü ayarlamak için herhangi bir yolu var mı yapabilir?

Yerine tam boy görüntü yükleme ve yeniden boyutlandırmak için HTML kullanarak daha, burada minik kullanmanın bir yolu da var mı?

1 Cevap

Bu sizin için ne arıyorsanız muhtemelen, bulunan here

function get_first_image() {
   global $post, $posts;
   $first_img = '';
   ob_start();
   ob_end_clean();
   $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i’, $post->post_content,    $matches);
   $first_img = $matches [1] [0];
   if(empty($first_img)){ //Defines a default image
      $first_img = “/images/default.jpg”;
   }
   return $first_img;
}