Home › Forums › Add-ons › Repeater Field › Unexp
I only want to show the first 25 rows of images, but my loop is breaking in the wrong place, and only shows 9 images using the code below. (Although does show 15 images when $maxNoImages is set to 15).
Can anyone help? Is it my loop itself that is wrong?
Thanks 🙂
James
<!-- Template Name: Embedded Album
-->
<!-- This is a single project album, embedded in a news post, with only the first 30 images showing to avoid pagination/infinite-scroll issues -->
<?php if ( post_password_required() ) { ?>
<form method="post" action="/wp-login.php">
<p>This content is password protected. To view it please enter your password below:</p>
<input type="password" style="margin:10px 0;" size="20" id="pwbox-<?php the_ID(); ?>" name="post_password"/></label><br/>
<input type="submit" value="Submit" name="Submit"/></p>
</form>
<?php } else { ?>
<!-- Show intro quote if entered, and not the Everything page -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if (get_the_content() != '') : ?>
<div id="projectheader" class="clearfloat">
<div class="quote">
<blockquote><?php the_content(); ?></blockquote>
</div>
</div>
<?php endif; ?>
<?php endwhile; endif; ?>
<!-- Photo album -->
<div id="photos" class="packery">
<div class="gutter-sizer"></div>
<div class="grid-sizer"></div>
<?php
// Variables
wp_reset_postdata();
$ref = $_SERVER['REQUEST_URI'];
$imageCounter = 0;
$maxNoImages = 25;
$embeddedPostID = get_the_ID();
$images = get_field('photos');
$total = count( $images );
echo 'total =' . $total;
// ACF Loop
if( have_rows( 'photos', $embeddedPostID) ) :
while( have_rows( 'photos') && $imageCounter < $maxNoImages ):
$row = the_row();
$imageCounter++;
// Lookup image details
$thumbnailID = $row['thumbnail'];
$photoID = get_sub_field( 'photo' );
$vimeo_video_id = $row['vimeo_video_id'];
// Vimeo ID but no thumbnail?
$thumblessVideo = false;
if ($vimeo_video_id !='' && $thumbnailID =='') {
$thumblessVideo = true;
};
// Check if image should be displayed double width
$doubleWidthThumb = $row['double_width_thumb'];
// Was small
$thumbnailType = $doubleWidthThumb ? 'medium' : 'shop_large';
if ($thumbnailID != '') {
$photoUrl = wp_get_attachment_image_src($thumbnailID, $thumbnailType);
$slideID = $row['thumbnail'];
} else {
$photoUrl = wp_get_attachment_image_src($photoID, $thumbnailType);
$slideID = $row['photo'];
}
// Disable double width thumbs if Everything page
$doubwidthThumbClass = ($doubleWidthThumb) ? ' w2' : '';
$thumblessVideoClass = ($thumblessVideo) ? ' video' : '';
echo '<div class="photo-thumb'. $doubwidthThumbClass . $thumblessVideoClass .'">';
// Now get the image and link it to the right slideshow page
if ($ref != '') {
echo '<a href="' . get_permalink() . 'detail/?ref=' . $ref . '#p' . $slideID .'">';
} else {
echo '<a href="' . get_permalink() . 'detail/#p' . $slideID .'">';
}
echo '<img src="' . $photoUrl[0] . '" />';
echo '</a>';
echo '</div>';
// if ( $imageCounter == $maxNoImages ) { break; };
endwhile;
?>
<!-- End Photos -->
</div>
<?php endif; ?>
<?php } ?>
Did you find a solution for this?
I looked over your code and to be honest I can’t see anything wrong with it.
I’ve found that at time PHP can have strange problems with conditions, I would try changing the while to
while( have_rows( 'photos') && ($imageCounter < $maxNoImages) ):
and maybe isolating that the second part will correct the error.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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.