下面的代码显示了wp gallery的所有图像及其大小,但它不是我想要的。
function get_images_high_data() {
$args = array(
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image/jpeg,image/jpg,image/png\',
\'post_status\' => \'inherit\',
\'posts_per_page\' => -1,
\'orderby\' => \'id\',
\'order\' => \'ASC\'
);
// Get all the available thumbnail sizes
$sizes = get_intermediate_image_sizes();
// Query the attachments
$query_images = new WP_Query( $args );
$images = array();
// Run a loop
if ( $query_images->have_posts() ){
while ($query_images->have_posts()){
$query_images->the_post();
// For each attachment size, store its URL in an array
foreach ( $sizes as $key => $size ) {
$thumbnails[$key] = wp_get_attachment_image_src( get_the_ID(), $size)[0];
}
$images = array_merge( $thumbnails , $images );
}
return $images;
}
}
返回的数组如下所示:
[0] => thumbnail-url,
[1] => medium-url,
[2] => large-url,
[3] => thumbnail-url,
[4] => medium-url,
[5] => large-url,
但当我设定
\'posts_per_page\' => 1
它是这样显示的
[0] => thumbnail-url,
[1] => medium-url,
[2] => large-url,
但我希望输出如下。
[0] => thumbnail-url,
如果我设置
\'posts_per_page\' => 2
它是这样显示的
[1] => medium-url,
[2] => large-url,