เอา แบบนี้แล้วกัน
เอา code นี้ไปใส่ใน function
// Get URL of first image in a post
function get_pic_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];
// no image found display default image instead
if(empty($first_img)){
$first_img = "/images/default.jpg";
}
return $first_img;
}
ส่วนตรงที่แสดงรูปภาพก็
<img src="<?php echo get_pic_image() ?>" alt="ใส่ alt ที่ต้องการ" width="ความกว้างที่ต้องการpx" height="ความสูงที่ต้องการpx"/>
จริงๆ code เหล่านี้ในนี้น่าจะมีแจงนานแล้วเน้อ ช่องขวาบน ช่วยได้จริง ๆ นะครับ
ปล. เว็บผมใช้แบบนี้ทุกเว็บ เลยชินกับ code ตัวนี้นิดหน่อย