How to get WordPress image thumbnail link? ( not featured image )

I am trying to build a simple gallery with WordPress Advanced Custom Fields and the repeater field plugin. I need to display a thumbnail image which you click to enlarge the main image (I am using Fancybox). Does anyone know whether it is possible to get the link to the image thumbnail WordPress automatically generates?

I can get the main image link:
/wp-content/uploads/2014/12/slide1.jpg

Read More

But need to get this image link:
/wp-content/uploads/2014/12/slide1-150×150.jpg

Here is my code:

<?php if(get_field('gallery')): ?>
    <ul>
        <?php while(has_sub_field('gallery')): ?>
            <a class="fancybox" href="<?php the_sub_field('image'); ?>" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet"><img src="<?php the_sub_field('image'); ?>" alt="" width="200px;" height="auto"/></a>
        <?php endwhile; ?>
        <?php while(has_sub_field('video_link')): ?>
            <a class="fancybox-media" href="<?php the_sub_field('video_link_snippet'); ?>"><img src="<?php the_sub_field('video_image'); ?>"/></a>
        <?php endwhile; ?>
    </ul>
<?php endif; ?>

Related posts

Leave a Reply

1 comment

  1. You can absolutely do this with Advanced Custom Fields and WordPress. To do so, go into the custom fields and change the sub field ‘image’ so that it returns the Image Object instead of the Image URL. See ‘return value’ here.

    Once this field returns the object, try var_dumping the field to see your URL options:

    var_dump(the_sub_field('image'));
    

    This should show you the different thumbnail sizes enabled in your system and allow you to easily get the thumbnail you’d like. One possible example:

    // Get image object with all sizes...
    $image = the_sub_field('image');
    $size = 'thumbnail';
    
    // Get URL from sizes based on our $size var
    $url = $image['sizes'][$size];
    
    // Now we have the thumbnail URL
    echo $url;
    

    Let me know if you run into problems! For more documentation and many more options, try the Advanced Custom Fields documentation for the Image field.