There might be other possibilities to this, mine is given below ..
-
First you use the
get_post_gallery
function to store the image id’s in a separate array ..if ( get_post_gallery() ) { $gallery = get_post_gallery( get_the_ID(), false ); $galleryIDS[] = array(); /* Loop through all the image and store them one by one */ foreach( $gallery['ids'] as $ids ) { $galleryIDS[] = $ids; } }
-
Then you output each image by id using
wp_get_attachment_image
as shown below ..<?php foreach ($galleryIDS as $key => $value ) { ?> <div class="galerija-box"> <a href="https://wordpress.stackexchange.com/questions/213601/<?php echo wp_get_attachment_image( $value,"medium' ) ?>" rel="lightbox"> <img src="https://wordpress.stackexchange.com/questions/213601/<?php echo wp_get_attachment_image( $value,"full' ) ?>"/> </a> </div> <?php } ?>
I didn’t test the code so it might have some syntax issues, but the method should work for you ..
EDIT
As mentioned before I didn’t check the code if its functional or not. So I tested it out, found a few bugs, fixed them. Below is the working code ..
if ( get_post_gallery() ) {
$gallery = get_post_gallery( get_the_ID(), false );
$galleryIDS = $gallery['ids'];
$pieces = explode(",", $galleryIDS);
foreach ($pieces as $key => $value ) {
$image_medium = wp_get_attachment_image_src( $value, 'medium');
$image_full = wp_get_attachment_image_src( $value, 'full');
?>
<div class="galerija-box">
<a href="https://wordpress.stackexchange.com/questions/213601/<?php echo $image_medium[0] ?>" rel="lightbox">
<img src="<?php echo $image_full[0] ?>"/>
</a>
</div>
<?php
}
}
?>
Reference: https://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src