<?php
$images =[];
$imagesArrays = [];
//The Loop
$loop = new WP_Query(array('post_type' => 'gallery',
'posts_per_page' => 100)
);
while ($loop->have_posts()) : $loop->the_post();
if (get_post_gallery()) :
$gallery = get_post_gallery(get_the_ID(), false);
/* Loop through all the image and output them one by one */
foreach($gallery['src'] as $src) : ?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
<?php
//Creates an Array Gallery Images from the Post
//Array (
// [0] => http://velnikolic.com/gallery/wp-content/uploads/2017/04/file4741298583098-1-1024x653.jpg
// [1] => http://velnikolic.com/gallery/wp-content/uploads/2017/04/file9221293737060-1024x683.jpg
// [2] => http://velnikolic.com/gallery/wp-content/uploads/2017/04/file4741298583098-1024x653.jpg
// )
$images = $gallery['src'];
endforeach;
endif;
//Push $images arrays into one array
$imagesArray = array($images);
print_r($imagesArray);
endwhile; wp_reset_query(); ?>
我想將圖像數組推入可通過鍵訪問的數組列表中。 $ imagesArray = array($ images);不附加$ images數組,只覆蓋它。將陣列推入陣列
$ imagesArray [] = $ images; – JYoThI