Only show first image in listing

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 20, 2009   (RSS)

Re: [RapidWeb] Only show first image in listing

By Chris - August 18, 2009 - edited: August 18, 2009

Hi RapidWeb,

You probably have a section like this in your list page:

<!-- STEP 2a: Display Uploads for field 'upload' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, ..., info1, info2, info3, info4, info5 -->
<?php foreach ($record['upload'] 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 endforeach ?>
<!-- STEP2a: /Display Uploads -->


The easiest way to change this so it displays only the first upload is to add a "break" statement just before the endforeach:

...
<?php endif ?>
<?php break; ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->


Hope this helps! Please let us know if you have any more questions.
All the best,
Chris

Re: [chris] Only show first image in listing

By (Deleted User) - August 20, 2009

Chris,

Thanks! Works wonders! What I love about Interactive Tools is that you don't need to be a programmer. Just follow the simple instructions. And when you do run into a small stag, the staff is here to help.