How To Publish Only Future Entries in Movable Type

| 3 Comments | No TrackBacks |
Since a blog consists mostly of a series of chronologically ordered items, it would seem to be a great format to build an events calendar or upcoming events list with.  And indeed, Movable Type llows you to set the publication date of entries into the future, either publishing them right away or at some future time (through scheduled publishing).  But how to publish a list of future entries only?
Suppose I have a blog with a number of entries in the past, and four future entries:

  • Future entry 1 (tomorrow)
  • Future entry 2 (the day after tomorrow)
  • Future entry 3 (next week)
  • Future entry 4 (in two months)
If I just ran an mt:entries loop in an index template, I would end up with this:

Future entry 4 - In two months

Future entry 3 - Next week

Future entry 2 - The day after tomorrow

Future entry 1 - Tomorrow

Past entry - Yesterday

Older entry - Last week

Oldest entry - Last month

Not exactly what I am looking for in an upcoming events list: I'm not interested in the stuff that is already in the past.  So how to hide the older entries?  There have been several suggestions in the past, many involving using advanced templating code or PHP to filter out entries whose date is in the past.

However, there is also the 'days' attribute to mt:entries, which according to the documentation:

Filters all posts less than N days old (the date when the page is published). N is a positive integer.

The days attribute should be used separately from other attributes. If used with another attribute, days is ignored.

So setting this to '0' (zero) wouldn't work, as this is not a positive integer.  Setting it to '1' will still include yesterday's entries. And indeed, tests confirm this.  But looking at the code here we see this:

        if ( my $days = $args->{days} ) {
            my @ago = offset_time_list( time - 3600 * 24 * $days, $blog_id );

That doesn't seem to require an integer, does it?  Any positive value should do, and the result of this calculation is a point in time before which all entries are ignored (this happens later in the code).  So if we make sure $days is very small, this point in time will be very close to 'now', exactly what we need.  So let's try this bit of template code:

<mt:entries days="0.0000000001">
<h4><mt:entrytitle> <mt:entrybody></h4>

Which results in:

Future entry 4 - In two months

Future entry 3 - Next week

Future entry 2 - The day after tomorrow

Future entry 1 - Tomorrow

Nice, only future entries!  But what if there are a lot of them?  Normally, people would be more interested in the next upcoming events, less the ones far into the future.  So let's add some more attributes:

<mt:entries days="0.0000000001" sort_order="ascend" limit="3">
<h4><mt:entrytitle> <mt:entrybody></h4>

This results in:

Future entry 1 - Tomorrow

Future entry 2 - The day after tomorrow

Future entry 3 - Next week

And there you have it: the next three future entries, with the earliest one first in the list, without any PHP or complicated templating code...

Note: if you want to make sure this list keeps current and automatically evolves over time, you need to either publish it dynamically or have it republished automatically every hour or so using the Bob the Rebuilder plugin.

No TrackBacks

TrackBack URL:


That's quite a hack, nice. :-)

Cool thing! In your case you are the only one who publishes entries and you know the right order for entries that reference future events. In a multi-author environment though you never know beforehand wich future event will be created when. So bear with me, imagine this scenario:

Entry 1, posted today 9 am, future date 1st of May
Entry 2, posted today 10 am, future date 1st of March
Entry 3, posted today 11 am, future date 1st of June

Desired order:

Entry 2 expiring on 2nd of March
Entry 1 expiring 2nd of May
Entry 3 expiring 2nd of June.

Which author posted which entry is irrelevant imho, but to sort out the right order is relevant. Do you know a way - maybe through custom fields? - how to achieve this?

Even if you don't have a solution for this problem, maybe you know where to get help? Thanks in advance!


It's remarkable to pay a visit this web site and reading the views of all colleagues concerning this piece of writing,
while I am also keen of getting experience.

Leave a comment