5

Is there a way where i can create a function that only displays expired entries? I have a page set up that displays, up and coming and pervious events click here when the user clicks on the pervious button it displays all past events.

{exp:channel:entries
            channel="events"
            disable="member_data|pagination|trackbacks"
            dynamic="no"
            sort="asc" 
            start_on="{current_time format='%Y-%m-%d %H:%i'}" 
            show_future_entries="no"
        }

i current have the tags above to display the events i have used the tag start_on to displays dates etc on the page. What tag(s) do i need to apply in order for my pervious template to display past events only?

5 Answers 5

3
{exp:channel:entries 
   show_expired="yes"
   stop_before="{current_time format='%Y-%m-%d %H:%i'}"
}
1
  • This doesn't work as the stop_before only controls dates. This will show you expired entries, plus any entries that are not expired made before this date.
    – Parscale
    May 16, 2014 at 21:42
3

To expound on my comment to this answer, and I acknowledge this is a bit unorthodox, this solution will improve performance by only executing one channel entries tag. The query tag will fetch the entry IDs, and dynamically build an embed variable that we will use on a single channel entries tag for this page request.

{exp:query sql="SELECT entry_id FROM exp_channel_titles WHERE expiration_date < {current_time} AND expiration_date != 0 AND channel_id = 9" limit="100"}
    {if count == 1}{embed="embeds/_expired_entries" entry_ids="{/if}
    {entry_id}{if count != total_results}|{/if}
    {if count == total_results}"}{/if}
{/exp:query}

The embed tag will only be created if the query has results, and the {embed:embed_ids} variable will contain something like 134|224|313|425

Then on the embeds/_expired_entries template we will put our channel entries tag, and feed it those entry IDs:

{exp:channel:entries channel="your_channel" status="open|closed" entry_id="{embed:entry_ids}" dynamic="no" show_expired="yes" disable="pagination|member_data|categories"}
    {title}, {custom_field}
    {pagination}{pagination_links}{/pagination}
{/exp:channel:entries}
4
  • 1
    Derek very creative, thanks. Question, why not have the pagination in the query tag? Will the channel tag paginate from a single entry_id list? I didn't think it would.
    – Parscale
    May 17, 2014 at 14:56
  • I couldn't yet test your suggestion on different versions, but on EECMS 2.5 it doesn't work. The empty spaces aren't trimmed. So, you need to put all in one single line or comment the spaces.
    – Sobral
    May 17, 2014 at 14:56
  • 1
    ExpressionEngine 2.5.0 is two years old. ;) May 18, 2014 at 15:43
  • It should, Parscale, as it just sets the filter for what entries to consider. Though you'd need to increase the limit on the outer query module, and use a limit on the inner channel entries tag to set the pagination if you are dealing with potentially hundreds of entries. May 18, 2014 at 15:46
2

If you use the expiration date in EE then all you need to do is set a conditional in the channel:entries tag that compares the expiration date to the current date like this:

{if expiration_date < current_time}
    display your content
{/if}

If you don't use expiration date but do have an {event_end_date} or similarly named field then you can swap expiration_date with {event_end_date}.

Also remove the start_on parameter from your channel:entries tag because this will keep previous entries from being parsed.

1
  • Works, but if you are paginating or doing something with thousands of entries, it will not work.
    – Parscale
    May 16, 2014 at 21:43
0

The only way to do this and keep pagination every 100 would be like so:

{exp:query sql="SELECT entry_id FROM exp_channel_titles WHERE expiration_date < {current_time} AND expiration_date != 0 AND channel_id = 9" limit="100"}
{exp:channel:entries channel="your_channel" status="open|closed" entry_id="{entry_id}" dynamic="no" show_expired="yes" limit="1" disable="pagination|member_data|categories"}
{title}, {custom_field}
{/exp:channel:entries}
{pagination}{pagination_links}{/pagination}
{/exp:query}

Brad

1
  • 2
    That's a lot of channel entries tags; up to 100 to be exact. What if you built an embed variable with the query module instead, and in the embedded template used that variable as the entry_id= parameter to one channel entries tag? May 16, 2014 at 22:06
0

I changed the code above to disinclude pagination and custom fields, and place the output in a numbered list, linking back to the CP/edit of each entry.

<ol>
{exp:query sql="SELECT entry_id FROM exp_channel_titles WHERE expiration_date < {current_time} AND expiration_date != 0"}
{exp:channel:entries status="open|closed" entry_id="{entry_id}" dynamic="no" show_expired="yes" limit="1" disable="pagination|member_data|categories" limit="1000"}
<li><a href="{site_url}admin.php?/cp/publish/edit/entry/{entry_id}">{title}</a></li>
{/exp:channel:entries}
{/exp:query}
</ol>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.