We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Today in History

How Do I?

jostar's avatar
jostar
36 posts
4 years ago
jostar's avatar jostar

Hi all.

I have a site with historic events and I wish to trigger and present history facts based on date.

i.e. if the date is 01/01/2021 I wish to show all the events that happened on 01/01 all the years before.

Any help?

btw. The new EE.6 is great!!!!!

       
Rob Allen's avatar
Rob Allen
2,950 posts
4 years ago
Rob Allen's avatar Rob Allen

You might be able to use a Date field here which comes with a day pickers but it’s sometimes a pain to enter really old dates.

What I’d look at doing is using 3 custom fields, one each for day, month and year. You could then query any day/month/year combination including just day & month (any year). You could extend that by adding another field for the actual day (Mon, Tue , Wed etc) for even more possibilities, you could even add another field for the time of day the event happened so you could show events that occured at midnight!

       
jostar's avatar
jostar
36 posts
4 years ago
jostar's avatar jostar

Rob thank you for you suggestion.

Maybe you can give me an example code of this query? Let’s say that I have 2 fields day/month how can I call them?

Best regards

       
Rob Allen's avatar
Rob Allen
2,950 posts
4 years ago
Rob Allen's avatar Rob Allen

There are many ways of doing this, here’s a couple of examples. I’m using month values as 01 to 12 and day values as 01 to 31 .

  1. Call directly into any template

This method might work best of you want it in a sidebar or footer.

Here we’re calling a regular channel entries loop for your “my_events” channel. Note how we’re using search: parameters with current_time variables to call in the current month and day.

{exp:channel:entries channel="my_events" search:my_month_field="{current_time format='%m'}" 
search:my_day_field="{current_time format='%d'}" dynamic="no"}
 {title} happend on this day
{/exp:channel:entries}
  1. Embedding inside another entry

This method is great if you have, say, a news story and want to show something for the same day/month that the story was posted.

Create a template for embedding, in that template add your events entries tag:

{exp:channel:entries channel="my_events" search:my_month_field="{embed:the_month}" 
search:my_day_field="{embed:the_day}" dynamic="no}

 {title} happend on this day

{/exp:channel:entries}</code></pre>

Note how we're using search: parameters here with embed: values.

Now call the embed template inside your news tag:

<pre><code>{exp:channel:entries channel="news" limit="1"}

    {title}

    {embed="template_group/template" the_month="{entry_date format='%m'}" the_day="{entry_date format='%d'}"}

{/exp:channel:entries}

What we’re doing here is using the entry_date of the news story to get month and day values.

πŸ‘ 1
       
jostar's avatar
jostar
36 posts
4 years ago
jostar's avatar jostar

Thank you very much….

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.