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
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 gkornbluth - April 30, 2011
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 ?>
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
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
Programmer
interactivetools.com
Re: [robin] limit number of images in listingDetails
By andybarn - May 7, 2011
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