Displaying single image from group
5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 21, 2008 (RSS)
By Thomas - November 20, 2008
I am using CMS v1.23 and I am trying to upload a bunch of pics.
I then want to show a single image (the first one uploaded) at the top of the page and then all the pictures in the form of a gallery.
How do I display just the single first uploaded image in a group.
Many thanks!
Re: [Thomas] Displaying single image from group
By Dave - November 21, 2008
If you look at the code generator output you'll see something like this that loops over images:
<?php foreach ($newsRecord['uploads'] as $upload): ?>
...
<?php endforeach ?>
The images are stored in $newsRecord['uploads'] and this loops over them assigning each one to $upload and displaying it.
You can assign the first image to a variable yourself like this:
<?php $firstImage = $newsRecord['uploads'][0]; ?>
Then display all the image fields just like you would inside the foreach loop. PHP starts counting some things at 0, which is why that is [0] and not [1].
Hope that helps!
interactivetools.com
Re: [Dave] Displaying single image from group
By Thomas - November 21, 2008
Really appreciate your help.
I tried, but I am still kinda stuck though...
So, in it's simplest form my current code is...
<?php foreach ($podcastsRecord['story_image'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<?php endforeach ?>
Where exactly do I put the
<?php $firstImage = $podcastsRecord['uploads'][0]; ?>
and what else do I have to do to get the first image?
Thank you
Re: [Thomas] Displaying single image from group
By Dave - November 21, 2008
Try this:
<?php $upload = $podcastsRecord['story_image'][0]; ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<?php foreach ($podcastsRecord['story_image'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<?php endforeach ?>
Let me know if that works for you.
interactivetools.com
Re: [Dave] Displaying single image from group
By Thomas - November 21, 2008
That worked a treat!
Thank you [:)]