Home Forums Add-ons Gallery Field Show the last few images of a gallery?


Show the last few images of a gallery?

  • How would you show the last 4 images of a gallery?

    In the example, I know how to show a 4 limit max, but showing the last 4 is a different story.

    $photos = get_sub_field(‘photos’);

    if( $photos ):
    $max = 4;
    $count = 0;

    foreach( $photos as $photo_id ):
    if ($count > $max):

    <?php wp_get_attachment_image( $photo_id, $size ) ?>
    <?php endforeach; ?>
    <?php endif; ?>

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.