Get the attachment ID 对于图像,然后获取post meta字段_wp_attachment_metadata
为了它。这是一个序列化数组。现场sizes
该数组中包含所有可用的图像大小。
伪代码:
$sizes = array();
$attachment_url = \'http://examle.com/wp-content-uploads/foo.png\';
$attachment_dir = dirname( $attachment_url );
$attachment_id = get_attachment_id( $attachment_url );
$attachment_meta = get_post_meta( $attachment_id, \'_wp_attachment_metadata\', TRUE );
$sizes[] = $attachment_url; // main file
if ( ! empty ( $attachment_meta[ \'sizes\' ] ) )
{
foreach ( $attachment_meta[ \'sizes\' ] as $size )
$sizes[] = "$attachment_dir/" . $size[ \'file\' ];
}