Support

Account

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

Unread

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.

    `
    <?php
    $photos = get_sub_field(‘photos’);

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

    foreach( $photos as $photo_id ):
    $count++;
    if ($count > $max):
    break;
    endif;
    ?>

    <ul>
    <li>
    <?php wp_get_attachment_image( $photo_id, $size ) ?>
    </li>
    <?php endforeach; ?>
    </ul>
    <?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.