Limit Upload Display - Mind Blank!

5 posts by 4 authors in: Forums > CMS Builder
Last Post: November 2, 2008   (RSS)

Hello, All -

I'm sure we must have covered this before - but here we go anyway...

On a List page, how do I limit the number of (image) uploads displayed with each record?

I've just created a Gallery category which features multiple sections spread over many pages. Each page includes a Title, some Content text and about 24 uploaded images.

The galleryList.php is the index from which visitors can access each gallery page. Alongside each link I would like to display a single random thumbnail image (from the corresponding section).

The basic code would be something like this...


<?php

require_once "/xyz/viewer_functions.php";

list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
));

?>


<?php foreach ($galleryRecords as $record): ?>

<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>


<?php foreach ($record['gallery_images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endif ?>
<?php endforeach ?>

<?php endforeach; ?>





It seems simple enough but I can't remember how to limit the number of thumbnails. Instead of a single image I get one of every picture in each gallery! The only way I've been able to control this is by inserting a <?php break; ?>[/#ff0000] - but this seems rather clumsy!

Surely there must be a more elegant way of controlling which and how many thumbnails are displayed?

:0)

Perch

Re: [Perchpole] Limit Upload Display - Mind Blank!

By Kenny - September 21, 2008 - edited: September 21, 2008

Perch,

The easiest thing I have found to do is to make a seperate "preview image" upload field. This way the user can choose which picture to show as the preview image. Limit this field to a one picture upload and code just this upload field into your list page.

I know this means you have to upload the same picture twice (once as a preview image and once as a gallery image) but it does make it understandable for most users.

As far as making this automatic, I haven't ever tried to code that so I'm not much help there.

Kenny

Re: [sagentic] Limit Upload Display - Mind Blank!

Hi, Kenny -

Thanks for your input. I've already gone down the route you suggested but (as you hi lighted) it seems like an necessarily repetitive step!

Ideally I'd like to be able to pluck out a random upload/image from the record and display it next to each entry on the listpage.

As with all things related to my CMS projects, I want to make the admin as easy (and as automated) as possible for the end-user - the client.

:o)

Perchpole

Re: [Perchpole] Limit Upload Display - Mind Blank!

By Dave - September 22, 2008

Hi perchpole,

If you know all your uploads are images and will have thumbnails you can remove this code:

<?php foreach ($record['gallery_images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endif ?>
<?php endforeach ?>


Next, if you want to show just one image you can use break like this to stop after just one:

<?php foreach ($record['gallery_images'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php break ?>
<?php endforeach ?>


And if you want a random image you can shuffle your array first:

<?php shuffle($record['gallery_images']) ?>
<?php foreach ($record['gallery_images'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php break ?>
<?php endforeach ?>


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