首先获取注册的图像大小和特色图像附件id:
$sizes = get_intermediate_image_sizes();
$post_thumbnail_id = get_post_thumbnail_id();
遍历已注册的大小并创建一个数组:
$images = array();
foreach ( $sizes as $size ) {
$images[] = wp_get_attachment_image_src( $post_thumbnail_id, $size );
}
组合为一个函数,用于放置内部函数。php:
function get_all_image_sizes($attachment_id = 0) {
$sizes = get_intermediate_image_sizes();
if(!$attachment_id) $attachment_id = get_post_thumbnail_id();
$images = array();
foreach ( $sizes as $size ) {
$images[] = wp_get_attachment_image_src( $attachment_id, $size );
}
return $images;
}
用法:
$featured_image_sizes = get_all_image_sizes();