Support

Account

Home Forums Add-ons Repeater Field Unexp

Helping

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.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Unexp’ is closed to new replies.