ถ้าเป็น WP นะ
เอา code นี้ไปใส่ใน function
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"/>