1

I am asking myself if there is a way of displaying a Channel Field based on date. I have a dedicated channel for the site's indexpage and randomly the client wants to display announcements eg for sweepstakes and the such.

Now I could put up a Field and a P&T Switch but I would like to have some kind of date logic so that the announcement disappears at a given time in the future.

Or should I really create a brandnew Channel just for announcements and pull those in the indexpage template? I can see the advantage of having sort of an Announcement archive then but it also feels a bit clumsy and overkill.

Any ideas on how to best do this logically, technically and best suited for client use?

Thanks and Cheers!

Marc

2

You could create an announcement field along with 2 date fields (start and end dates).

{if current_time > announcement_start_time && current_time < announcement_end_time}
  {announcement}
{/if}
2

Two things to look at:

Have your client set an "Expiration Date" on the entries. If show_expired="" is not set to "yes" on the entries tag, then these entries will automatically stop showing on the website at the set time/date.

Use the start_on="" parameter to set a start date for the entries tag. Only entries from that date forward to present will show. To set a dynamic start date, you'll need to use PHP like this:

<?php
    $start_time = $this->EE->localize->decode_date('%Y-%m-%d %H:%i', $this->EE->localize->now - 86400);
?>
{exp:channel:entries channel="{my_weblog}" limit="5" sort="desc" start_on="<?php echo $start_time; ?>"}
0

Thanks Anna and Jason. I managed to solve this issue with Matrix in the end like this:

{if cell_1 >= current_time}
    {cell_2}
{/if}

Where cell_1 is a "Date" Cell Type and cell_2 is a "Text" Cell Type.

Since Jason's answer is correct and not relies on using third-party Modules I'll mark it as the accepted answer.

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.