我可以获得如下图像的URL列表:
$sizes = array_merge(array(\'full\'),get_intermediate_image_sizes());
foreach ($sizes as $imageSize) {
$image_attributes = wp_get_attachment_image_src( $post->ID , $imageSize );
echo $imageSize . \':<br>\' .$image_attributes[0].\'<br>\';
}
这让我
full:
http://domain.com/wp-content/_uploads/2014/01/my_image.png
thumbnail:
http://domain.com/wp-content/_uploads/2014/01/my_image-150x150.png
medium:
http://domain.com/wp-content/_uploads/2014/01/my_image-300x116.png
我想要的是
full:
/path/to/public_html/wp-content/_uploads/2014/01/my_image.png
thumbnail:
/path/to/public_html/wp-content/_uploads/2014/01/my_image-150x150.png
medium:
/path/to/public_html/wp-content/_uploads/2014/01/my_image-300x116.png
最合适的回答,由SO网友:Craig Pearson 整理而成
这应该可以达到您想要的效果,但是请注意,结果路径名中会有反斜杠和正斜杠。如果这导致web服务器出现问题,您可能需要进一步执行str_replace
使用反斜杠向前斜杠的步骤
有关详细信息,请参见代码中的注释
$sizes = array_merge(array(\'full\'),get_intermediate_image_sizes());
$uploads = wp_upload_dir();
foreach ($sizes as $imageSize) {
// Get the image object
$image_object = wp_get_attachment_image_src($post->ID,$imageSize );
// Isolate the url
$image_url = $image_object[0];
// Using the wp_upload_dir replace the baseurl with the basedir
$image_path = str_replace( $uploads[\'baseurl\'], $uploads[\'basedir\'], $image_url );
// echo it out
echo $imageSize . \':<br>\' .$image_path.\'<br>\';
}