我想在WordPress中更新IModelBinder
,以便它适合feedburner。它需要找到每个img标签,看它是否设置了宽度和高度。如果它们大于600,它们应该减少到600.如果它们没有设置,那么宽度应该设置为600.我想使用一些代码here来做它,但我有点卡住了,我很感激帮助修复它。
问题:
如何找到width为null - 在哪种情况下添加它?
the_content_rss
答案 0 :(得分:1)
In function.php add the following function:
function aq_resize($url,$width,$height=null,$crop=null,$single=true){
$up_info=wp_upload_dir();
$up_dir=$up_info['basedir'];
$up_url=$up_info['baseurl'];
if (strpos($url,home_url()) === false){return false;}
$rel_path = str_replace( $up_url, '', $url);
$img_path = $up_dir . $rel_path;
if (!file_exists($img_path) OR ! getimagesize($img_path)){return false;}
$info = pathinfo($img_path);
$ext = $info['extension'];
list($orig_w,$orig_h) = getimagesize($img_path);
$dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
$dst_w = $dims['4'];
$dst_h = $dims['5'];
$suffix="{$dst_w}x{$dst_h}";
$dstrel=str_replace('.'.$ext,'',$rel_path);
$dest="{$up_dir}{$dstrel}-{$suffix}.{$ext}";
if($width >= $orig_w) {
if(!$dst_h) :
$img_url=$url;
$dst_w=$orig_w;
$dst_h=$orig_h;
else :
if(file_exists($dest) && getimagesize($dest)) {
$img_url="{$up_url}{$dstrel}-{$suffix}.{$ext}";
}
else {
$resized=resize_image($img_path,$width,$height,$crop);
$resized_rel=str_replace($up_dir,'',$resized);
$img_url=$up_url.$resized_rel;
}
endif;
}
elseif(file_exists($dest) && getimagesize($dest)) {
$img_url="{$up_url}{$dstrel}-{$suffix}.{$ext}";
}
else {
$resized=resize_image($img_path,$width,$height,$crop);
$resized_rel=str_replace($up_dir,'',$resized);
$img_url=$up_url.$resized_rel;
}
if($single) {
$image = $img_url;
} else {
$image = array (
0 => $img_url,
1 => $dst_w,
2 => $dst_h
);
}
return $image;
}
In a place where the need conclusion miniatures, write the following, changing the size of the thumbnails on the right for you:
<img src="<?php echo aq_resize(first_img(),180,130,true)?>