下面的函数计算文件大小,只需更改“/myfile/image”。jpg\'和您的特色图像变量。
<?php
function file_size($url){
$size = filesize($url);
if($size >= 1073741824){
$fileSize = round($size/1024/1024/1024,1) . \'GB\';
}elseif($size >= 1048576){
$fileSize = round($size/1024/1024,1) . \'MB\';
}elseif($size >= 1024){
$fileSize = round($size/1024,1) . \'KB\';
}else{
$fileSize = $size . \' bytes\';
}
return $fileSize;
}
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
//echo file_size(\'/myfile/image.jpg\');
echo file_size($feat_image);
?>
然后退房
WP Codex