Reputation: 5784
I am using following code to get the images loaded into a post gallery. this is working and returning images but all in small size 150 x 150 px
Can you please let me know how I can modify the code to return the original size of the images in galley?
I have seen some post here at Stack Exchange but they all are dealing mostly with thumbnails
not WordPress Galley
<?php
/* The loop */
while ( have_posts() ) : the_post();
if ( $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="w-100" alt="Gallery image" />
<?php
}
endif;
endwhile;
?>
Upvotes: 1
Views: 360
Reputation: 360
get_post_gallery() also returns ids
of the images as string. So one way of doing it will be to explode those ids, loop through them and use wp_get_attachment_image_src() which accept any registered image size name, or an array of width and height values in pixels.
<?php
while ( have_posts() ) : the_post();
if ( $gallery = get_post_gallery( get_the_ID(), false ) ) :
$ids = explode(',', $gallery['ids']);
// Loop through all the ids and output image one by one.
foreach ( $ids as $id ) {
$img = wp_get_attachment_image_src($id, 'full');
?>
<img src="<?php echo $img[0]; ?>" class="w-100" alt="Gallery Image">
<?php
}
endif;
endwhile;
?>
Upvotes: 1