Feature most recent file upload

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 18, 2008   (RSS)

Re: [jdancisin] Feature most recent file upload

By zip222 - July 18, 2008

my post is so lonely [:|]

Re: [jdancisin] Feature most recent file upload

By Dave - July 18, 2008

jdancisin,

Thanks for your patience!

Can we assume that the "newest" upload will always be sorted to the top? If so you could just use two viewers and a counter to keep track of the upload we're displaying. Here's the code:

<h1>File Viewer 1</h1>
<ul>
<?php $uploadCount = 0; ?>
<?php foreach ($customRecord['archived_files'] as $upload): ?>
<?php if (++$uploadCount > 1) { continue; } ?>
<li><a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['info1'] ?>...</a></li>
<?php endforeach ?>
</ul>

<h1>File Viewer 2</h1>
<ul>
<?php $uploadCount = 0; ?>
<?php foreach ($customRecord['archived_files'] as $upload): ?>
<?php if (++$uploadCount < 2) { continue; } ?>
<li><a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['info1'] ?>...</a></li>
<?php endforeach ?>
</ul>


A little explanation for the code. The ++$variable means "add one to this" and "continue" means skip the rest and continue with the next item in the foreach.

And if you want them in reverse order (with the bottom upload showing first, just replace _both_ foreach lines with this:

<?php foreach (array_reverse($customRecord['archived_files']) as $upload): ?>

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