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.

Display single entry based on custom date field

November 07, 2012 5:40am

Subscribe [2]
  • #1 / Nov 07, 2012 5:40am

    tomjeatt

    19 posts

    I have this code which filters a list of conferences and returns only those which haven’t already finished. It works fine:

    <ul>
     {exp:channel:entries channel="conference" sort="asc" orderby="conference_start_date"}
      {if "{conference_end_date}" >= "{current_time}"}
      <li>
       <a href="http://{title_permalink=conferences/conference}">{title}</a>
      </li>
      {/if}
     {/exp:channel:entries}
    </ul>

    The problem is I want to only display the first entry on this list (i.e. the event which ends soonest). Because the channel entries are being parsed before the if statement runs, using limit=“1” results in no entries. Is there a way around this? Using the entry date for the start date won’t work, as these entries are created and used long before the conferences actually start. Similarly, changing the status to closed won’t work because these pages are used after the conference has ended. Any ideas?

  • #2 / Nov 07, 2012 11:51am

    Rob Allen

    3105 posts

    If each conference date is a single entry then you could use Entry date combined with the start_on and show_future_entries parameters:

    <ul>
    {exp:channel:entries channel="conference" sort="desc" start_on="{current_time format='%Y-%m-%d %H:%i'}" show_future_entries="yes" limit="1"}
    
      <li>
       <a href="http://{title_permalink=conferences/conference}">{title}</a>
      </li>
    
     {/exp:channel:entries}
    </ul>
  • #3 / Nov 07, 2012 5:17pm

    Dan Decker

    7338 posts

    Hi Tom,

    Did Rob’s suggestion work for you?

    ~

  • #4 / Nov 08, 2012 4:32am

    tomjeatt

    19 posts

    Hi Dan/Rob - not exactly 😉 The order in which the events are created isn’t the order in which they take place, so using entry_date by itself didn’t help. I came across the event helper plugin though (http://devot-ee.com/add-ons/eevent-helper), which let me clone the custom date field to the entry date, so that the entry dates matched the order in which they take place. That let me use something similar to Rob’s code:

    <ul>
       {exp:channel:entries channel="conference" show_future_entries="yes" sort="asc" orderby="entry_date" show_future_entries="yes" limit="1"}
       <li><a href="http://{title_permalink=conferences/conference}">{title}</a></li>
    {/exp:channel:entries}
    </ul>

    I had to rejig some other templates, but taking advantage of the entry_date and expiry_date fields (cloned from the custom date fields) actually gave me greater flexibility than I had before. So thanks!

  • #5 / Nov 08, 2012 4:21pm

    Dan Decker

    7338 posts

    Hey Tom!

    Excellent!

    If you need anything else, just let us know.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases