I need to get the URL (actual Size) of all images of gallery associated with a post in single.php
. The following code from Codex returns all images in very small size 150×150 which is not suitable for what I want
<?php
while ( have_posts() ) : the_post();
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
foreach( $gallery['src'] AS $src )
{
?>
<img src="https://wordpress.stackexchange.com/questions/175156/<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
<?php
}
endif;
endwhile;
?>
Then I find following method which retuns the images in actual size BUT return all images in the Galleries (Not only images within the galley of current Post)
<?php
global $post;
$thumbnail_ID = get_post_thumbnail_id();
$images = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
print_r( $images );
if ($images) :
foreach ($images as $attachment_id => $image) :
if ( $image->ID != $thumbnail_ID ) :
$img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); //alt
if ($img_alt == '') : $img_alt = $image->post_title; endif;
$big_array = image_downsize( $image->ID, 'large' );
$img_url = $big_array[0];
echo '<li>';
echo '<img src="';
echo $img_url;
echo '" alt="';
echo $img_alt;
echo '" />';
echo '</li><!--end slide-->';
endif; endforeach; endif;
so I tried to retrieve this by adding $post_id = get_the_ID();
to cede as:
<?php
global $post;
$thumbnail_ID = get_post_thumbnail_id();
$post_id = get_the_ID();
$images = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
print_r( $images );
if ($images) :
foreach ($images as $attachment_id => $image) :
if ( $image->ID != $thumbnail_ID ) :
$img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); //alt
if ($img_alt == '') : $img_alt = $image->post_title; endif;
$big_array = image_downsize( $image->ID, 'large' );
$img_url = $big_array[0];
echo '<li>';
echo '<img src="';
echo $img_url;
echo '" alt="';
echo $img_alt;
echo '" />';
echo '</li><!--end slide-->';
endif; endforeach; endif;
but now I am getting only white page without any on the page! Can you please let me know why this is happening and how I can fix this? Thansk