Use two upload fields in a listing

5 posts by 3 authors in: Forums > CMS Builder
Last Post: July 8   (RSS)

By furcat - July 6

I am working on a site for a teacher providing lessons online that can be downloaded. On one of the pages, we have book "covers" and an associated PDF file for download. I created a multi-record section editor with an upload field for the photo/image and an upload field for the PDF. 

My question/problem. On the listing page, I want to display the image with the correct link to the PDF. There may be an actual detail page in the future, but right now I just want to show the image with a link that brings up the PDF.

Since these are upload fields, I'm struggling with the logic of getting those two sets of information together. 

Ideas and suggestions are welcome!

Here's the page on the website:

(yes, it has errors ... I'm not finished with it yet)

Thank you!

By Deborah - July 6

Hi, furcat,

Here's how I would set that up:

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

<?php foreach ($record['pdf'] as $index => $upload): ?>

<a href="<?php echo htmlencode($upload['urlPath']) ?>">

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

<?php endforeach ?>
<?php echo htmlencode($record['title']) ?>

<?php endforeach ?>

All of the above code is available in the CMSB Code Generator - it just needs to be juggled around to wrap the image with the PDF urlPath.

~ Deborah

By gregThomas - July 7 - edited: July 7

Hey Furcat,

To expand on Deborah's answer a bit, I'd create two upload fields, one that contains the book cover image called 'cover_image' and one that contains the book PDF called 'pdf'. I'd limit the fields so that each can only contain one upload. With this setup, Deborah's code would return one image and pdf per book record.



Greg Thomas

PHP Programmer -

By furcat - July 8

Thank you! Worked perfectly. I really appreciate it.

Now I need to figure out how to make two columns .....