limit number of images in listingDetails

4 posts by 3 authors in: Forums > CMS Builder
Last Post: May 7, 2011   (RSS)

By andybarn - April 29, 2011

Hi

I am creating a Realty site using the Basic Realty Add On.

I have created a 3 column table to display the images 3
accross and this works well. However I want to limit the
number of images displayed here to 12 images max. This
would give me a 3 x 4 table and if there were more than 12
images the ones after 12 would be left off. Hope you can
help.

Re: [andybarn] limit number of images in listingDetails

By robin - May 2, 2011

Hey,

You can break the image loop when you've reached the image limit you want. Something like this, at the top of your image loop:
<?php $counter=0; ?>
<?php foreach ($realtyRecord['uploads'] as $upload): ?>
<?php $counter++; ?>
<?php if($counter > 20): ?>
<?php break; ?>
<?php endif; ?>


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] limit number of images in listingDetails

By andybarn - May 7, 2011

Hi Robin

Sorry for the late reply - I have only just got back to this.

Your code was just what I needed to get this sorted. The only thing I changed was substituting

<?php foreach ($realtyRecord['uploads'] as $upload): ?>

for

<?php foreach ($listing['uploads'] as $upload): ?>

and everything worked as I wanted - fantastic! I can now limit the number of images displayed by changing the number in

<?php if($counter > 20): ?>


Great support!

Thanks to you and Jerry for your input and help.

Andy