dimanche 29 mars 2015

Advanced Custom Fields Repeater With 2 Loops

I am setting up a photo gallery, with a main image and 6 thumbnails under it. Upon hovering the thumbnail, the main image will change. Simple stuff. The problem I am having is that when the page loads, the main image is the image from the first repeater row (like I want), but then in the thumbnails, the first repeater row doesn't get output. So only thumbnails 2 - 6 are being output. I am new to Advanced Custom Fields. Not sure if it's something to do with that or if it's just a simple PHP error. Here is my code:



<?php if( have_rows('property_images') ):

while( have_rows('property_images') ): the_row();

$image = get_sub_field('property_image');
$url = $image['url'];

?>

<img src="<?php echo $url ?>" class="property-main-img">

<?php
break;
endwhile;
endif;
?>

<ul>

<?php if( have_rows('property_images') ):

$i = 1;

while( have_rows('property_images') ): the_row();

$image = get_sub_field('property_image');
$url = $image['url'];

?>

<?php if($i % 3 == 0) { ?>

<li class="prop-thumb-r"><img src="<?php echo $url ?>" alt="<?php echo $image['alt']; ?>" width="170" /></li>

<?php } else if($i == 1 || $i % 4 == 0) { ?>

<li class="prop-thumb-l"><img src="<?php echo $url ?>" alt="<?php echo $image['alt']; ?>" width="170" /></li>

<?php } else { ?>

<li><img src="<?php echo $url ?>" alt="<?php echo $image['alt']; ?>" width="170" /></li>

<?php } ?>

<?php
$i++;
endwhile;
endif;
?>

</ul>

Aucun commentaire:

Enregistrer un commentaire