Displaying a combination of first upload only and all uploads on same page

11 posts by 5 authors in: Forums > CMS Builder
Last Post: December 7, 2017   (RSS)

Hey guys,

I have a page where I'm trying to pull in all uploads for all records but to only display the first upload too...

ie. I need the first upload of each record to be the 'button' which when clicked will trigger a pop up windiw which then displays all uploads for that record. What's the best way to achieve this and hop ethat makes sense?

Thanks!

By Dave - September 27, 2017

Hi Kittybiccy, 

The best way to start with anything like this is to mock it up in plain html first.  Then once you get it working exactly how you want it figure out how to recreate the HTML with PHP.

Here's some basic counter code you can add to any foreach loop to show some difference content for the first result:

  <?php $myCounter = 0; ?>
  <?php foreach ($records as $record): ?>
    <?php $myCounter++; ?>
    
    <?php if ($myCounter == 1): ?>
      <p>This is the first record
      <?php showme($record); ?>
    <?php endif ?>

    <?php if ($myCounter > 1): ?>
      <p>These are records after the first
      <?php showme($record); ?>
    <?php endif ?>
  <?php endforeach ?>

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

Hi Dave,

Thank you for this - I'm struggling to get it to work though. Here is a link to the HTML page:
http://www.llewellynharker.com/MERCER3/work.html

And here is my php page:
http://www.llewellynharker.com/MERCER4/work.php

You'll see the difficulty is to just get the one image to display and that trigger the pop up window which then displays the full batch of images for each record. Any ideas?

By Damon - October 3, 2017

Hi,

We have your email with details. Will take a look and get back to you with suggestions.

Thanks!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Damon - October 4, 2017

Just a follow-up for anyone else, you can limit the uploads displayed to just the first one for each record by adding the code into the uploads foreach:

<?php if ($index >= 1) { continue; } // limit uploads shown ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Dave - October 10, 2017

Clever! 

Dave Edis - Senior Developer
interactivetools.com

Is there a way of doing something similar with text? I have a page where I want to show various project categories, but if there is, say, two projects in the same category, that category's title appears twice: http://dordanmech.com/projects.php

This is the code I'm using:

<ul id="filter-porto">
<li class="space"></li>
<li class="filt-projects" data-project="*">View All</li>
<li class="space"></li>

<?php foreach ($projectsRecords as $record): ?>
<li class="filt-projects" data-project=".<?php echo $record['category'] ?>"><?php echo $record['category:label'] ?></li>
<li class="space"></li>
<?php endforeach ?>

</ul>

By Mikey - December 6, 2017

Howdy CSD,

This might do the trick... I haven't tested this code, but I have something similar to it running.

<ul id="filter-porto">
    <li class="space"></li>
        <li class="filt-projects" data-project="*">View All</li>
            <li class="space"></li>
<?php $recordCounter = 0; ?>
    <?php foreach ($projectsRecords as $record): ?>
    <?php $recordCounter++; ?>
            <?php if ($recordCounter == 0): ?><!-- apply to first instance -->
                <li class="filt-projects" data-project=".<?php echo $record['category'] ?>"><h1><?php echo $record['category:label'] ?></h1></li>
                <li class="space"></li>
            <?php elseif ($recordCounter == 1): ?><!-- apply to second instance -->
                <li class="filt-projects" data-project=".<?php echo $record['category'] ?>"><h3><?php echo $record['category:label'] ?></h3></li>
                <li class="space"></li>
            <?php else: ?><!-- apply to remaining instances -->
                <li class="filt-projects" data-project=".<?php echo $record['category'] ?>"><p><?php echo $record['category:label'] ?></p></li>
                <li class="space"></li>
            <?php endif; ?>
    <?php endforeach ?>
</ul>

Zicky

By Dave - December 7, 2017

Hi CommonSenseDesign, 

Try this: 

<ul id="filter-porto">
  <li class="space"></li>
  <li class="filt-projects" data-project="*">View All</li>
  <li class="space"></li>

  <?php foreach ($projectsRecords as $record): ?>
    <?php if (@$alreadySeen[ $record['category'] ]++) { continue; } // skip categories we've already seen ?>
    <li class="filt-projects" data-project=".<?php echo $record['category'] ?>"><?php echo $record['category:label'] ?></li>
    <li class="space"></li>
  <?php endforeach ?>
</ul>

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com