Reverse foreach order
2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 10, 2009 (RSS)
By bruno - February 10, 2009
I've got lightbox running on my page that links to the image gallery from a thumbnail. For some reason they lightbox image are loading in reverse order. The caption says 3 of 3 when it should say 1 of 3. I was wondering if there is a way to reverse the foreach order.
Thanks!
Niki
<?php
require_once "/Documents/design/Brunello-Redesign/dev/cmsAdmin/lib/viewer_functions.php";
list($web_portfolioRecords, $web_portfolioMetaData) = getRecords(array(
'tableName' => 'web_portfolio',
));
?>
<?php foreach ($web_portfolioRecords as $record): ?>
<div class="grid_4">
<!-- begin lightbox link -->
<?php
foreach ($record['main_images'] as $upload): ?>
<?php if ($upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" rel="lightbox[web1<?php echo $record['title'] ?>]" title="Record title: <?php echo $record['title'] ?>" >
<?php endif ?>
<?php endforeach ?>
<!-- Begin Thumbnail Image -->
<?php
foreach ($record['thumbnail'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" class="portfolioImg" /></a><!-- end lightbox link -->
<?php endforeach ?><!-- end thumbmail for each -->
<!-- links for lightbox -->
<?php
foreach ($record['main_images'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" rel="lightbox[web2<?php echo $record['title'] ?>]" title="Record title: <?php echo $record['title'] ?>" ></a>
<?php endforeach ?>
<!-- end links for lightbox -->
<h3><?php echo $record['title'] ?></h3>
<?php echo $record['project_description'] ?>
<!-- begin view more link -->
<p>
<?php
foreach ($record['main_images'] as $upload): ?>
<?php if ($upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" rel="lightbox[web3<?php echo $record['title'] ?>]" title="Record title: <?php echo $record['title'] ?>" >
<?php endif ?>
<?php endforeach ?>View More »</a></p>
<!-- end view more link -->
Thanks!
Niki
Re: [bruno] Reverse foreach order
By Dave - February 10, 2009
Hi Niki,
You can reverse the order of an array (or list of images) like this:
<?php foreach (array_reverse($web_portfolioRecords) as $record): ?>
Give that a try and if you're still having troubles feel free to email me CMS and FTP login details to dave@interactivetools.com and I can take a look. (Email, don't post login details the forum).
Hope that helps!
You can reverse the order of an array (or list of images) like this:
<?php foreach (array_reverse($web_portfolioRecords) as $record): ?>
Give that a try and if you're still having troubles feel free to email me CMS and FTP login details to dave@interactivetools.com and I can take a look. (Email, don't post login details the forum).
Hope that helps!
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com