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.

Show only entries that are expired?

January 18, 2009 7:24pm

Subscribe [6]
  • #1 / Jan 18, 2009 7:24pm

    Kevin Smith

    4784 posts

    I need to be able to show entries that are expired, but ONLY entries that are expired. In my sidebar, I’ve got a “Current Event” link and a “Past Events” list. This is for an art gallery, and there is only one exhibition at a time, but there may be times where there isn’t an exhibition at all, so I can’t just use the offset parameter for the past events list.

    Basically, I need the past events list to show all expired entries, but ONLY expired entries. I know it’s not part of the standard weblog module, but is there an plugin/extension or anything that’ll help do this? Perhaps EllisLab can think about adding this parameter to the EE2.0 channel module? 😉

  • #2 / Jan 18, 2009 7:57pm

    Kevin Smith

    4784 posts

    I’ve got it working, but I had to use PHP to make it happen. (Thanks to Mark in this thread for the boost.) Yikes, that was a bear. Still, it would be nice to have show_only_expired as a weblog (or channel) parameter in EE2.0! Hint!

    Just thought I’d post back to help others in case they’re wondering the same. It’s a bit convoluted—and if anyone’s got a suggestion to make it cleaner, then great—but here’s what my code looks like:

    {exp:weblog:entries weblog="{my_weblog}" show_future_entries="no" show_expired="yes" sort="asc" orderby="date" status="open" dynamic="off"}
    <?php
    
    $current_date = "{current_time format='%Y%m%d'}";
    $expiry_date = "{expiration_date format='%Y%m%d'}";
    if ($expiry_date >= $current_date)
    {
    echo '<h4>Current Exhibition</h4>
    <p><ul id="sidebar_nav">';<br />
    }</p>
    
    <p>?><br />
    {/exp:weblog:entries}</p>
    
    <p>{exp:weblog:entries weblog="{my_weblog}" show_future_entries="no" show_expired="yes" sort="asc" orderby="date" status="open" dynamic="off"}<br />
    <?php</p>
    
    <p>$current_date = "{current_time format='%Y%m%d'}";<br />
    $expiry_date = "{expiration_date format='%Y%m%d'}";<br />
    if ($expiry_date >= $current_date)<br />
    {<br />
    echo '<li><span class="plus">+</span> <a href="http://{url_title_path=\\artists/details\\}">{title}</a></li>';<br />
    }</p>
    
    <p>?><br />
    {/exp:weblog:entries}</p>
    
    <p>{exp:weblog:entries weblog="{my_weblog}" show_future_entries="no" show_expired="yes" sort="asc" orderby="date" status="open" dynamic="off"}<br />
    <?php</p>
    
    <p>$current_date = "{current_time format='%Y%m%d'}";<br />
    $expiry_date = "{expiration_date format='%Y%m%d'}";<br />
    if ($expiry_date >= $current_date)<br />
    {<br />
    echo '</ul>';<br />
    }</p>
    
    <p>?><br />
    {/exp:weblog:entries}</p>
    
    <p>{exp:weblog:entries weblog="{my_weblog}" show_future_entries="no" show_expired="yes" sort="asc" orderby="date" status="open" dynamic="off"}<br />
    <?php</p>
    
    <p>$current_date = "{current_time format='%Y%m%d'}";<br />
    $expiry_date = "{expiration_date format='%Y%m%d'}";<br />
    if ($expiry_date < $current_date)<br />
    {<br />
    echo '</p><h4>Past Exhibitions</h4>
    <p><ul id="sidebar_nav">';<br />
    }</p>
    
    <p>?><br />
    {/exp:weblog:entries}</p>
    
    <p>{exp:weblog:entries weblog="{my_weblog}" show_future_entries="no" show_expired="yes" sort="asc" orderby="date" status="open" dynamic="off"}<br />
    <?php</p>
    
    <p>$current_date = "{current_time format='%Y%m%d'}";<br />
    $expiry_date = "{expiration_date format='%Y%m%d'}";<br />
    if ($expiry_date < $current_date)<br />
    {<br />
    echo '<li><span class="plus">+</span> <a href="http://{url_title_path=\\artists/details\\}">{title}</a></li>';<br />
    }</p>
    
    <p>?><br />
    {/exp:weblog:entries}</p>
    
    <p>{exp:weblog:entries weblog="{my_weblog}" show_future_entries="no" show_expired="yes" sort="asc" orderby="date" status="open" dynamic="off"}<br />
    <?php</p>
    
    <p>$current_date = "{current_time format='%Y%m%d'}";<br />
    $expiry_date = "{expiration_date format='%Y%m%d'}";<br />
    if ($expiry_date < $current_date)<br />
    {<br />
    echo '</ul>';<br />
    }</p>
    
    <p>?><br />
    {/exp:weblog:entries}

    Explanation: If there aren’t any current exhibitions, then that ul block won’t show. Same for the past exhibitions block. My script assumes that something expiring today is still current. Tomorrow it won’t be. I used %Y%m%d instead of %U because the art gallery’s exhibitions would expire at the end of the day, not literally down to the minute of the entry.

  • #3 / Jan 18, 2009 8:11pm

    Mark Bowen

    12637 posts

    Hi Kevin,

    Glad to have been of assistance 😉
    Well in a round-a-bout sort of way anyway!!

    Thanks for sharing that code, I’m sure it will help a lot of people out who want to do the same sort of thing. Might be an idea to put in a feature request for that parameter you mention. Could be useful that one.

    Best wishes,

    Mark

  • #4 / Jan 18, 2009 8:13pm

    Kevin Smith

    4784 posts

    Well you know, I get a lot of help out of these forums, so if I can at all be of help to others, I try to be! Thanks for all the stuff you’ve thrown into this forum. It’s been loads of help to me!

  • #5 / Jan 18, 2009 8:27pm

    Mark Bowen

    12637 posts

    Well you know, I get a lot of help out of these forums, so if I can at all be of help to others, I try to be! Thanks for all the stuff you’ve thrown into this forum. It’s been loads of help to me!

    No problem at all. As you say we all chip in whenever we can. 😊

  • #6 / Jan 22, 2009 11:05am

    GKenny

    78 posts

    Hey guys,

    I might be missing something really obvious,  but wouldn’t this be easier:

    {if current_time > expiration_date}
        The entry {title} is expired!
    {/if}

    Please correct me if I’m wrong!

  • #7 / Jan 22, 2009 11:15am

    Mark Bowen

    12637 posts

    Hey guys,

    I might be missing something really obvious,  but wouldn’t this be easier:

    {if current_time > expiration_date}
        The entry {title} is expired!
    {/if}

    Please correct me if I’m wrong!

    Yep that’s the same sort of thing I did in the post that was linked to above.

  • #8 / Jan 22, 2009 11:18am

    GKenny

    78 posts

    {if current_time > expiration_date}
        The entry {title} is expired!
    {/if}

    Yep that’s the same sort of thing I did in the post that was linked to above.

    Yeah, but in this version, I’m only using EE tags and functions and there is no need for PHP parsing. I’m my case, I needed PHP parsing in input, so it wasn’t an option to me!

  • #9 / Jan 22, 2009 12:24pm

    Mark Bowen

    12637 posts

    Oops yep see what you mean although with mine I was needing to set the date formatting for each variable so had to use PHP or you get into all sorts of weirdness trying to use them inside an {if} conditional.

  • #10 / Apr 15, 2009 10:51pm

    mahalie

    60 posts

    I was attempting to something very similar to the original poster. It would be really nice if we could select which date field to use for evals of all types -> start_on, stop_before, etc. Or at least add an option on ‘show_expired’ to =“only”. Here was the simplest (I think) method for me…perhaps custom SQL would be cleaner, in any case:

    {exp:weblog:entries orderby="expiration_date" sort="desc" paginate="bottom" weblog="events" status="Published|Featured" show_expired="yes" show_future_entries="no" limit="15"}
    
    {if current_time > expiration_date}
       Do your stuff here for expired only entries.
    {/if}
    {/exp:weblog:entries}

    This is far from perfect, if you limit to 10, for example, you will not necessarily display 10 entries because you are pulling before evaluating and not all of the returned items are necessarily expired. This should really be a where clause/limit in the weblog:entries tag somehow.

  • #11 / Apr 16, 2009 5:03am

    Mark Bowen

    12637 posts

    Perhaps a feature request might be in order here? 😉

    Best wishes,

    Mark

  • #12 / Jan 11, 2010 10:43am

    Andrew Philpott

    18 posts

    Does anybody know of a way to achieve something like this, but to also limit the number of expired entries? I need to only show the 3 most recent expired entries on a project I’m working on.

  • #13 / Apr 20, 2010 7:21pm

    Whit Nelson

    5 posts

    You would need to use something like the PHP solution above and use a counter, since the limit parameter will only limit the amount of entries headed into the expiration logic. Like this:

    {exp:weblog:entries limit=3} <—This will send up to 3 into the loop
      {if current_time > expiration_date} <—But this may prune some of them off, leaving possibly less than 3
          {title}
      {/if}
    {/exp:weblog:entries}

    Whit

  • #14 / Mar 27, 2013 4:18am

    infomani28

    5 posts

    I tried it works BUT the pagination doesn’t work.  Please provide a better solution for displaying expiry entries.

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

ExpressionEngine News!

#eecms, #events, #releases