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.

How to display entries from the same date but different years.

October 14, 2011 5:52am

Subscribe [2]
  • #1 / Oct 14, 2011 5:52am

    Liberty

    13 posts

    I’ve posted about this before but received no response, so I thought I’d give it a try here to see if anyone had any suggestions.

    A long time ago with EE 1 I had an plugin called “On This Day” by Yoshi from http://psychodaisy.com/ and I can’t seem to find a replacement that would work for EE2

    Essentially, the plugin would take a date of the entry you were reading on an individual entry page and spit out other entries written on that date in other years.  If one went to an entry written on 10/14/2011 there would be a little blurb at the bottom like, “Written on this date in other years…” and then links and a short preview of other entries that had been written on 10/14 in future/past years.

    I’m not sure how I would ask EE how to pull that information.

    Any suggestions would be greatly appreciated!

  • #2 / Oct 24, 2011 9:31pm

    John St-Amand

    865 posts

    I know how to display only entries with a date that matches, but that’s not quite what you’re looking for, since that would require the entries tag to loop through the entire channel and display only the ones that share the same month and date.  While it would technically work, it’s far less efficient than it should be.  Really what you want, as you suggest, is a plugin that does the search for you.

    If you just don’t care about the efficiency of it, here’s how you would display the items sharing the same date just using native EE an entries loop.

    {exp:channel:entries channel="whatever" orderby="date" sort="desc" limit="1" disable="whatever you can afford to disable"}
    
    Your entry info
    
    {embed="embeds_template_group/also-on-this-date" the_date="{entry_date format="%m%D"}"}
    
    {/exp:channel:entries}

    And then in the embedded template:

    {exp:channel:entries channel="whatever" orderby="date" sort="desc" disable="whatever you can afford to disable"}
    
    {if '{the_date}' == '{entry_date format="%m%D"}'}
    
    {if count=="1"}Written on this date in other years{/if}
    
    {entry_date format="%Y"}
    {title}
    {abstract}
    {other_custom_fields}
    
    {/if}
    
    {/exp:channel:entries}

    But as I mentioned, this isn’t ideal.  I suspect the query module would give you the ability to conduct the search for the entries sharing the same entry month and day while ignoring year, but it’s not something I know how to do, I’m afraid.  Perhaps just having a reply that moves this to the top of the pile post-EECI will help get a response for you.  You could also post a question to Twitter with the hash tag #eecms - lots of community members watch that thread and respond from there.

    Cheers,
    John

  • #3 / Oct 24, 2011 10:40pm

    John St-Amand

    865 posts

    I posted a tweet and got a reply right away.  @dreamtime suggested this, because EE does actually store the month, day and year separately in the db tables:

    {exp:channel:entries channel="whatever" orderby="date" sort="desc" limit="1" disable="whatever you can afford to disable"}
    
    Your entry info
    
    {embed="embeds_template_group/also-on-this-date" the_entry_month="{entry_date format="%m"}" the_entry_day="{entry_date format="%D"}"}
    
    {/exp:channel:entries}

    And then in the “also-on-this-date” embedded template:

    {exp:query sql="SELECT entry_id, url_title, abstract_field FROM exp_channel_titles WHERE month = {the_entry_month} AND day = {the_entry_day}"}
    
    <a href="#">{title}</a>
    {abstract_field}
    
    {/exp:query}

    I’m not certain this would work as I have it laid out here, but @dreamtime gave the syntax for the query portion and that should pull the entries from the right month/day regardless of what year they come from (which would mean other entries even from the current year would show too if they’re on the same month/day).

    Please let me know if this helps/works.

  • #4 / Oct 24, 2011 10:50pm

    John St-Amand

    865 posts

    Ok, this is going to sound silly after all that, but year, month and day are each separate available parameters on the entries tag pair.  So really, i can’t think of a reason you could just use those.  They should have the effect of a search for the most part.  You’d still need to do the embed, since you need to have an entries loop within the main entries loop, but this should be much simpler:

    {exp:channel:entries channel="whatever" orderby="date" sort="desc" limit="1" disable="whatever you can afford to disable"}
    
    Your entry info
    
    {embed="embeds_template_group/also-on-this-date" the_entry_month="{entry_date format="%m"}" the_entry_day="{entry_date format="%D"}"}
    
    {/exp:channel:entries}

    And then there embed would look like:

    {exp:channel:entries channel="whatever" orderby="date" month="{embed:the_entry_month}" day="{embed:the_entry_day}" sort="desc" disable="whatever you can afford to disable"}
    
    {if count=="1"}Written on this date in other years{/if}
    
    {entry_date format="%Y"}
    {title}
    {abstract}
    {other_custom_fields}
    
    {/exp:channel:entries}
  • #5 / Jul 27, 2012 7:46am

    Liberty

    13 posts

    I’m not entirely sure how I missed this.  I made attempts to use the above code with no luck.  Much sad faces. 

    If I use this code on my index page, which only shows the single most recent entry, it seems to display the same month/year entries.

    If I use it on an individual entry (comment) page, then it only works for the current year, which means any entries written prior to 2012 show nothing and any entries written in 2012 only show other 2012 entries written on the same day - in other words, the same entry. 

    And yeah, years later, I STILL want to be able to do this. Heh.  Oh well.

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

ExpressionEngine News!

#eecms, #events, #releases