1

I have the below loop and would like to print a specific thumbnail size, as this loop currently prints the full size image. How would I print a smaller thumbnail?

while ( have_posts() ) : the_post();
    get_template_part( 'content', 'page' );
endwhile; // end of the loop. 

$rows = get_field( 'gallery' );
if ( $rows ) { 
    ?><ul id="galleryList" class="fullWidth"><?php 
    foreach( $rows as $row ) { 
        ?><li class="galleryBox">
            <a href="<?php echo $row['link_to_gallery']; ?>">
                <img src="<?php echo $row['image']; ?>">
            </a>
        </li><?php 
    } 
    ?></ul><?php 
} // endif

1 Answer 1

1

You can define your own post thumbnail sizes

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150 );

This means that you change the thumbnail size overall.

Or you can define custom image sizes

add_action( 'after_setup_theme', 'wpdocs_theme_setup' );
function wpdocs_theme_setup() {
    add_image_size( 'category-thumb', 300 ); // 300 pixels wide (and unlimited height)
    add_image_size( 'homepage-thumb', 220, 180, true ); // (cropped)
}

and call it like:

if ( has_post_thumbnail() ) { 
    the_post_thumbnail( 'category-thumb' ); 
}
2
  • So would the code be: '<a href="<?php echo $row['link_to_gallery']; ?>"> <img src="if ( has_post_thumbnail() ) { the_post_thumbnail( 'category-thumb' ); }"> </a>'
    – iamonstage
    Commented Oct 13, 2015 at 19:15
  • Remember to enclose php code into <?php ?> and then call it like <a href="<?php echo $row['link_to_gallery']; ?>"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'category-thumb' ); } ?> </a>
    – julia
    Commented Oct 13, 2015 at 20:06

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.