ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Sorting pictures with matching dates into galleries?

December 02, 2014 10:00am

Subscribe [2]
  • #1 / Dec 02, 2014 10:00am

    Victor Paredes

    7 posts

    I am attempting to build galleries of photos based on {photo_date}, a custom field containing the date on which each photo was taken. My list of photos looks something like this:

    Photo#   {photo_date}
        1        11/1/14
        2        11/1/14
        3        11/1/14
        4        11/16/14
        5        11/16/14
        6        11/22/14

    My goal is to have a loop that allows only one photo to appear from each date “group.” This photo will serve as the photo group’s cover image. So, after running the script, I will end up with this:

    Group 1: Photo#1 (11/1/14)
    Group 2: Photo#4 (11/16/14)
    Group 3: Photo#6 (11/22/14)

    I am attempting to use a php variable inside of an EE loop to check to see if it matches:

    <?php $clip = "0"; ?>
                   {exp:channel:entries channel="event_photos" dynamic="no" sort="asc" orderby="photo_date" search:photo_date="not IS_EMPTY"}
              <div class="clear floatnone">
               {if "{photo_event}{photo_event:url_title}{/photo_event}" == "<?php echo $currentSegment; ?>"} <!-- filter only this event's photos -->
                Before add: <?php echo $clip; ?>
    
                {if "{photo_date format='%m/%d/%y'}" != "<?php echo $clip; ?>"}
                 {title}
    
                 <a href="http://{photo}" title="{photo_caption}">{photo}</a>
                {/if}
                <?php $clip = "{photo_date format='%m/%d/%y'}"; ?>
                After add: <?php echo $clip; ?>
    
               {/if}
              </div>
              {/exp:channel:entries}

    I think this should work, but it doesn’t. It seems that the PHP variable ($clip) is getting assigned at the end of the {if} loop, but gets erased at the beginning once the loops starts over. This prevents me from checking to see if the {photo_date} in question has been used or not in the previous iteration. I’m wondering how to get the variable to retain the intended value?

    I appreciate any thoughts or maybe a more elegant solution!


  • #2 / Dec 03, 2014 12:23pm

    Giraffentoast

    152 posts

    Buenas Victor,

    First, let me recommend Channel Images to you. If you got the money, it’s really worth it. Image sizes, quality, sorting, galleries, cover images, hue, saturation,... it covers all. I’m not affiliated with them, btw.

    That said, let’s see. Without access to Channel Images, here’s what I would do in your case:

    Ditch the photos channel. Create a channel galleries, that consists of a date field and a grid field with a single file field.

    Create as many galleries as you want, and sort the images within each gallery by drag and drop. You can even name your galleries via the channel’s title field.

    In the template, loop over all galleries (sort by date field) and display the first image of each. No need for comparing dates, no need for PHP.

    The template markup would look something like this:

    {exp:channel:entries channel="galleries" orderby="gallery_date" sort="desc" dynamic="no" disable="categories|category_fields|member_data|pagination"}
    
    {gallery_images limit="1"}
     <a href="/gallery/{url_title}">_ {gallery_images:gallery_images_file}__ {title} ({gallery_date})</a>
    {/gallery_images}
    
    {/exp:channel:entries}

    Untested, of course.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases