0

Unsure how to get this... I need to display from a gigantic list of events, sorted by start-date but only displaying 1 event that is set to happen the soonest but not already ended.

{if entry_date >= current_time}
    {title}
{/if} 

The above shouldn't work because the limit applies before the loop. Any thoughts?

0

You can use the start_on parameter within the channel entries tag. Something like:

{exp:channel:entries
    channel="channel_name"
    limit="1"
    sort="asc"
    start_on="{current_time format='%Y-%m-%d %H:%i'}"
    show_future_entries="yes"
}
2
  • switching from desc to asc and that worked like a charm! – brunam Jul 2 '13 at 18:06
  • Awesome, I'll edit my answer. – Siebird Jul 2 '13 at 18:10
0

You could use the free Solspace add-on called Date Field Filter. It would allow you to dynamically set a start date of current_time which would then be future-friendly in the way you're looking for.

1
  • The difference between this one and the answer above is that this one would allow you to use a custom field for your start and end date, and not have to use your publish date (which I prefer to maintain separately for publishing control). Date Field Filter allows you to map a custom field to the usual date behaviour of the entries loop without using the publish date. Just a matter of what suits your needs. – Jean St-Amand Jul 2 '13 at 19:04
0

Using the start_on and stop_on has flexibility without using an add-on. Add a bit of PHP to increase your options. I frequently want to display just entries that are dated either in the next and/or last 7 days. You need to allow PHP on input in the template. Change the 604800 to however many seconds you want the time period to be.

<?php
$start_time = $this->EE->localize->format_date('%Y-%m-%d %H:%i', $this->EE->localize->now - 604800);
?>
<?php
$stop_time = $this->EE->localize->format_date('%Y-%m-%d %H:%i', $this->EE->localize->now + 604800);
?>

{exp:channel:entries channel="channel_name" show_future_entries="yes" dynamic="no" start_on="<?php echo $start_time; ?>" stop_before="<?php echo $stop_time; ?>" orderby="entry_date" sort="desc"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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