I have the following code:

if (themedy_get_option('product_gallery')) { add_action('genesis_post_content', 'themedy_product_images', 1); }
function themedy_product_images() { ?>
    global $post;
    $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 999, 'order'=> 'ASC', 'orderby' => 'menu_order' ) ); 
    if ( $images ) { ?>
<div class="twocol-one">
<?php echo get_the_post_thumbnail( $post->ID, 'product-400x600' ); ?>
    <div class="product_images">
        <div class="container">
            foreach ( $images as $image ){
                $gallery_image_info = wp_get_attachment_image_src( $image->ID, 'full' );
                $gallery_image = $gallery_image_info[0];

                $gallery_thumb_info = wp_get_attachment_image_src( $image->ID, 'Gallery Thumb' );
                $gallery_thumb = $gallery_thumb_info[0];

                $gallery_image_alt = get_post_meta($image->ID, '_wp_attachment_image_alt', true) ? trim(strip_tags( get_post_meta($image->ID, '_wp_attachment_image_alt', true) )) : trim(strip_tags( $image->post_title ));

                echo '<a href="'.$gallery_image.'" title="'.$gallery_image_alt.'" class="fancybox" rel="single-gallery"><img src="' . $gallery_thumb . '" /></a>';

Issue #1: Where it says:

<?php echo get_the_post_thumbnail( $post->ID, 'product-400x600' ); ?>

I need it to say

<a id="product" class="MagicZoomPlus" href=" <?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?> " rel="selectors-class: Active"><img src=" <?php echo get_the_post_thumbnail( $post->ID, 'product-400x600' ); ?> " alt="" /></a>`

Where it echo's the images (large and product-400x600), I need it to only echo the img url, without all the other html that comes with it. How can i fix my above code to have it rendered the way I require?

Issue #2: Where it says:

echo '<a href="'.$gallery_image.'" title="'.$gallery_image_alt.'" class="fancybox" rel="single-gallery"><img src="' . $gallery_thumb . '" /></a>';

It is a loop of all the other images in that gallery. For each image in the loop.. I need it to say

<a class="Selector" href="<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>" rel="zoom-id:product" rev="<?php echo get_the_post_thumbnail( $post->ID, 'medium' ); ?>"><img src="' . $gallery_thumb . '" alt="" /></a>

Again, same issue as #1 where I need it to echo just the image url/src.

The way it should function is like in this example: http://www.magictoolbox.com/magiczoomplus/

Thank you in advance!


My first attempt as per Brian's suggestion below for the featured image, works!

    $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
    $image2 = wp_get_attachment_image_src(get_post_thumbnail_id(), 'product-400x600');
<?php echo '<a id="product" class="MagicZoomPlus" href="'.$image[0].'" rel="selectors-class: Active"><img src="'.$image2[0].'" alt="" /></a>'; ?>

Now the question is, how do I go about this for the image gallery items?

1 Answer 1


Here are the functions you need to be aware of:

Example sans size:

echo wp_get_attachment_url(get_post_thumbnail_id());

Example with size:

$image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo $image[0]; //as HREF in your A tag

You can grab all of the gallery images as follows:

$args = array(
    'order'=> 'ASC',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID,
    'post_type' => 'attachment'

$attachments = get_children( $args );

foreach($attachments as $attachment){
    //use $attachment->ID to retrieve attachment information
    $image = wp_get_attachment_image_src($attachment->ID, 'large');
  • Thank you for the reference. So how does that fit in to the loop? ie: how do I know which thumbnail id is for the large, medium and small version of which image?
    – iCeR
    Commented Feb 27, 2012 at 5:26
  • Thanks for the update on reference to the get_attachment_image_src! That's perfect for the featured image, but how do I do that for the loop of thumbnail images in the gallery? Sorry for not understanding the concept more easily- trying to wrap my head around it.
    – iCeR
    Commented Feb 27, 2012 at 5:29
  • Check out the latest edit and see if that helps out. Commented Feb 27, 2012 at 5:43
  • See my attempt at the bottom of my question.. harder than I first though..
    – iCeR
    Commented Feb 27, 2012 at 6:50
  • Ok I figured out that out by reading your suggestion properly :) Code is in my question - maybe you can suggest optimising it better? Just struggling now with the image gallery images..
    – iCeR
    Commented Feb 27, 2012 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.