第一步:在functions.php文件里添加以下函数
//文章列表缩略图
function emtx_auto_thumbnail($pID,$thumb='thumbnail') {
$blogimg = FALSE;
if (has_post_thumbnail()) {
$blogimg = wp_get_attachment_image_src(get_post_thumbnail_id($pID),$thumb);
$blogimg = $blogimg[0];
} elseif ($postimages = get_children("post_parent=$pID&post_type=attachment&post_mime_type=image&numberposts=0")) {
foreach($postimages as $postimage) {
$blogimg = wp_get_attachment_image_src($postimage->ID, $thumb);
$blogimg = $blogimg[0];
}
} elseif (preg_match('/
]*src=["|\']([^"|\']+)/i', get_the_content(), $match) != FALSE) {
$blogimg = $match[1];
}
if($blogimg) {
$blogimg = '
';
}
return $blogimg;
}
第二步:在首页和文章列表页文件中添加以下代码
ID) ) {
echo emtx_auto_thumbnail($post->ID);
} ?>
第三步:在style.css文件中添加如下代码
/* 缩略图*/
.thumbnail {
position: relative;
float: left;
margin: 6px 10px 0 0;
}
.thumbnail a img {
width: 200px;
height: 130px;
}