如果将图像插入(附加)帖子而不是外部链接:
function get_my_thumbnail($post_id, $size, $attr = \'\'){
// check of featured image first
$t = get_post_thumbnail_id($post_id);
// no featured image set, check post attachments
if(empty($t)){
$attachments = get_children(array(
\'post_parent\' => $post_id,
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'order\' => \'ASC\',
\'orderby\' => \'menu_order ID\',
));
$attachment = array_shift($attachments); // we only need one
$t = $attachment ? $attachment->ID : false;
}
// no attachments either...
if(empty($t)) return \'no image...\';
// we have either attachment / featured image, so output the post thumbnail
do_action(\'begin_fetch_post_thumbnail_html\', $post_id, $t, $size); // compat
$html = wp_get_attachment_image($t, $size, false, $attr);
do_action(\'end_fetch_post_thumbnail_html\', $post_id, $t, $size);
return $html;
}
您可能还想
regenerate all attachment sizes (自动创建
$size
-d图像),所以您不会在浏览器中调整大图像的大小。。。