Image on listing page

4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 28, 2009   (RSS)

Re: [vyskocil] Image on listing page

By Dave - January 27, 2009

Hi vyskocil,

You'll have two foreach loops on your list page. The first one loops over your listing records and displays them. Then inside of that there will be one that loops over the images for each listing and display those.

Inside the second foreach add this right before the "endforeach":

<?php break; ?>

And that will make it "break" out of the image foreach loop after showing just one image.

If you still have any troubles with it attach the viewer file and we can take a look.

Hope that helps.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Image on listing page

HI Dave,

That is one of the suggestions that I found in the forum and tried. I did try that again in case I had it in the wrong place. And you are correct that it stops the loop after one image. Then I get NO image for the second, third, etc. listings. I get only the one image on the first listing only. The rest of the listings list all the info but no images. When I remove the <?php break; ?> that I just added then I am back to showing all the images for all the listings. What I would like is this. If I have 5 listings and each has 5 pictures I want the 5 listings to show on the listings page but I want only the first image of each listing to show. I only need to show all the images on the listingDetail page. Your answer seems to indicate that the loop for the images is nested inside the loop for the listing. That is not the way it appears the code is generated. It has a step2 display records which has an endforeach and then a step2a display uploads. Both seem to be independent loops and not nested. So can you help me out a little more. My code is displayed below:

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Listings - List Page Viewer</h1>
<?php foreach ($realty_listingRecords as $record): ?>
Record Number:
<?php echo $record['num'] ?>
<br/>
Featured Property:
<?php echo $record['featured'] ?>
<br/>
Property Type:
<?php echo $record['property_type'] ?>
<br/>
Price:
<?php echo $record['price'] ?>
<br/>
MLS #:
<?php echo $record['mls'] ?>
<br/>
Address:
<?php echo $record['address'] ?>
<br/>
City:
<?php echo $record['city'] ?>
<br/>
State / Province:
<?php echo $record['state'] ?>
<br/>
Summary:
<?php echo $record['summary'] ?>
<br/>
Description:
<?php echo $record['description'] ?>
<br/>
<br>
View Listing : <a href="<?php echo $record['_link'] ?>">
<?php echo $record['_link'] ?>
</a><br/>
<hr/>
<?php endforeach; ?>
<?php if (!$realty_listingRecords): ?>
No records were found!<br/>
<br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
</td>
<td>
<!-- STEP 2a: Display Uploads for field 'uploads' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
<?php foreach ($record['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download
<?php echo $upload['filename'] ?>
</a><br/>
<?php endif ?>
<?php break; ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->

Re: [vyskocil] Image on listing page

By Dave - January 28, 2009

Hi vyskocil,

No problem, copy and paste "Step 2a" just above this code:

<?php endforeach; ?>
<?php if (!$realty_listingRecords): ?>

Then it should work properly. Alternatively you can try creating a new list viewer code with the code generator. The code must have gotten shuffled around some how.

If that doesn't work for you let me know and we can take a closer look.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com