Support

Account

Home Forums ACF PRO Get different image size after 5th item

Solved

Get different image size after 5th item

  • Hello!

    My goal is to create a gallery to print out a different sized image after 5th image.
    Is it even possible to do that?

  • Are you using a gallery field or some other type of image field? A gallery field returns an array of image objects. An example is given on this page http://www.advancedcustomfields.com/resources/gallery/

    You’d basically need to create a loop to loop through the array and then change the image you used after the 5th one.

    
    for ($i=0; $i<count($images); $i++) {
      if ($i<5) {
        $size = 'thumbnail';
      } else {
        $size = 'large';
      }
      echo $images[$i]['sizes'][$size],'<br>';
      echo $images[$i]['sizes'][$size.'-width'],'<br>';
      echo $images[$i]['sizes'][$size.'-height'],'<br>';
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Get different image size after 5th item’ is closed to new replies.