Creating Future Entry Archives In ExpressionEngine

Sep. 23, 2008

4:25 pm

ExpressionEngine's exp:weblog:month_links function is one of those basic blog tools you'd expect any leading software to include. It's main responsibility is generating a list of links to monthly archive pages. But like a number of ExpressionEngine's core functions, turns out it's actually less flexible than the core system itself.

See, EE makes it dead easy to mark an entry with a future date and still display that entry on public-facing pages. Whether you create a custom date field and future date that or you use the entry date field attached to every entry by default, all posts are accessible. The problem is that tags like exp:weblog:month_links don't play nice with future dates.

The situation.

Recently, I was working on a client site that needed to include a list of future events with some sub-navigation that included links to monthly event summaries for each of the next 12 months. In other words: a future entry archive. If the event date is past, I wanted the event to disappear without any action on the part of the client. If there are no more events for a given month, I wanted that month to disappear from the sub-navigation.

The list of events was easy. All I had to do is add the show_future_entries parameter to exp:weblog:entries. But exp:weblog:month_links has no such parameter.

The solution.

Well, exp:weblog:entries does what I need. Why not exploit it? Here's what I ended up doing:

  1. <div class="widget">
  2. <h3>Events By Month</h3>
  3. <ul>
  4. {exp:weblog:entries weblog="calendar" start_on="{current_time format='%Y-%m-%d %g:%i %A'}" show_future_entries="yes" sort="asc" limit="999" dynamic="off"}
  5. {date_heading display="monthly"}
  6. <li><a href="/club/calendar/{year}/{month}"{if segment_4 == month} class="on"{/if}>{entry_date format="%F, %Y"}</a></li>
  7. {/date_heading}
  8. {/exp:weblog:entries}
  9. </ul>
  10. </div>

There are a couple fun tricks going on here. First, the start_on parameter does exactly what you'd expect – lets you explicitly set a date where your query results should start. In this case, we're using EE's handy current_time global variable to fetch the current time. That's how we ensure that only future dated entries will ever show up. Events that have already happened just aren't returned by our query. And as mentioned above, we've set the show_future_entries parameter to yes.

But the piece that's most germane to this conversation is that date_heading bit. In most cases, you'd use a date heading to segment a list of entries – just like I do throughout this site. But in this case, we're not actually posting any entry data to the page. The date heading is, in fact, all we're printing. Get it? Just a date for each month's worth of results, and voila – instant monthly archive. We just put a link around the results and point it towards the "calendar" template in the "club" group. In this case, I've got some php in that template that knows how to handle date based requests.

But that's for another post.


June 26, 2009

6:06 pm

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful and beneficial to your readers.

Max Glipmax (#)

March 31, 2010

11:38 pm

Good work! Thanks

True Blood (#)

Whaddya think?