如何获取gallery里面的图片及id并遍历出来

Published
May 11, 2022
浏览次数 :  0

<div class=”g-context”>

<?php

$gallery = get_post_gallery( get_the_ID(),false );

$gallery_image_ids = explode(‘,’, $gallery[‘ids’]);

echo “<pre>”;

var_dump($gallery_image_ids);
echo “</pre>”;

foreach ($gallery_image_ids as $id) :
$image = wp_get_attachment_image_src( $id,’customerThumbnail’ );

echo “<pre>”;

var_dump($image[0]);

echo “</pre>”;

?>

<?php endforeach; ?>

</div>


Top