Search code examples
wordpressimagethumbnailsimage-sizepodscms

How to turn images into thumbnail size using foreach loop in Wordpress Pods CMS


I am using Wordpress Pods CMS and I have a foreach loop to show an unordered list of images. I would like to turn the images into thumbnail size (using the WordPress media thumbnail settings in the dashboard).

My code currently look like this...

<ul>
<?php
foreach ($thePod->get_field('images') as $photo) {
  echo "<li><img src=\"{$photo['guid']}\" alt=\"{$name}\" /></li>";
}
?>
      <?php else:?>
      <p>no photos</p>
      <?php endif;?>
</ul>

I tried putting .... "{$photo['guid'], 'thumbnail'}" but that doesn't work and I know this usually works ... "wp_get_attachment_image_src($image['0']['id'], 'thumbnail');" when I want to display one image only.


Solution

  • try this:

    foreach ($thePod->get_field('images') as $photo) {
      $thumbnail = wp_get_attachment_image_src( $photo[ID], 'thumbnail' );
      echo "<li><img src='$thumbnail[0]' alt='$name' /></li>";
    }
    

    mkm