limit number of images in listingDetails

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

Re: [andybarn] limit number of images in listingDetails

Hi Andybarn,

Here’s a recipe from my CMSB cookbook http://www.thecmsbcookbook.com that should help.

There are a lot more tips and tricks on how to utilize the power of CMS Builder on you sites.

Hope that gets you going in the right direction.

Best,

Jerry Kornbluth

_______________________________________

LIMITING THE NUMBER OF IMAGES ON A PAGE AND SHOWING CODE IF EXCEEDED

I wanted to show only a certain number of thumbnails on a page (20) and display a link to a second page if that number was exceeded. The limit part was easy. In the get records code at the top of the page I entered

'limit' => '20',
To display a message if the number was exceeded, (in this case a link to a second viewer) I used the following: ( I was already using a counter on this page so I called this counter count2)
<?php $count2 = 0; ?>
<?php foreach ($portfolio_imagesRecords as $record): ?>
<?php $count2++; ?>
<?php endforeach; ?>

<?php if ($count2 >19): ?><a href=”http://www.your_site.com/your_viewer2.php”>Click for more images.><?php endif ?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

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