Showing selective images
3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 25, 2014 (RSS)
By JeffC - November 4, 2014
Please can someone advise me how to show selected images
So instead of the code below which shows all uploads I would like to skip uploads 1 and 2 and begin with upload 3:
<?php if ($page['photos']): ?>
<?php foreach ($page['photos'] as $upload): ?>
<div class="thumbnail">
<img src="<?php echo $upload['thumbUrlPath2'] ?>" width="100%" title="<?php echo htmlspecialchars($upload['info1']) ?>" alt="<?php echo htmlspecialchars($upload['info3']) ?>" /><?php if ($upload['info1']): ?>
<div class="caption"><?php echo htmlspecialchars($upload['info2']) ?></div>
<?php endif ?>
thanks
By rconring - November 4, 2014
Try this:
<?php if ($page['photos']): ?>
<?php $imageCount = 0 // Initialize counter ?>
<?php foreach ($page['photos'] as $upload): ?>
<?php $imageCount ++ // Increment the counter ?>
<?php if($imageCount < 3):continue // slip first 2 array elements ?>
<div class="thumbnail">
<!-- Image display code -->
</div>
<?php endforeach ?>
<?php endif ?>
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987
By JeffC - November 25, 2014
Hi Ron
Thank you for your idea. It didn't quite work out for me but it got me on the right track. For anyone else that may be looking for a solution here's what i did:
<?php if ($page['photos']): ?>
<?php $uploadCount = 0; ?>
<?php foreach ($page['photos'] as $upload): ?>
<?php if (++$uploadCount < 3) { continue; } ?>
<div class="thumbnail">
<!-- Image display code -->
</div>
<?php endforeach ?>
<?php endif ?>