มีใครพอจะ แปลออกไหมครับว่ามันทำงานอย่างไร หรือ หลักการอย่างไร
code 1
function postimage($width,$height) { $scriptpath = get_bloginfo('template_directory');
$attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
$img = array_shift($attachments);
$imagelink = wp_get_attachment_image_src($img->ID,'full');
$image = $imagelink[0];
if($image=='') {
$image = $scriptpath."/images/default.gif";
echo '<img src="'.$scriptpath.'/scripts/timthumb.php?src='.$image.'&w='.$width.'&h='.$height.'&zc=1" alt="" />';
}else {
echo '<img src="'.$scriptpath.'/scripts/timthumb.php?src='.$image.'&w='.$width.'&h='.$height.'&zc=1" alt="" />';
}
}
/* --------------------------------------------- */
code 2
function get_post_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]
if(empty($first_img)){
$img_dir = get_bloginfo('template_directory');
$first_img = $img_dir . '/images/thumb.gif';
}
return $first_img;
ขอบคุณมากครับ