Help - Search - Members - Calendar
Full Version: Non-Consecutive Dates - How To
Movable Type Community Forum > Additional Resources > Tips and Tricks
Christine
Thanks for posting a way to do this!  It looks great and will be *really* helpful on my blogs that don't get posted to very often!
Dori
Thanks, Mena!!!
Mena Trott
Dori, over at Backup Brain recently posed a question that has made its round through the board on previous occasions.

We didn't have an answer before -- but we do now.

The question: How can I set my blog to post entries from a last n amount of non-consecutive days.

Here's how to do it:

Your archiving method should be set at daily and your index would basically be an archive limited to the last seven days of posts.

A little more detail:

1. If you don't already have daily archiving turned on, turn it on

2. Instead of using just
   
CODE
   <MTEntries>
   ...
   </MTEntries>
   

which is the usual way to list entries in an index template, you would use
   
CODE
   <MTArchiveList archive_type="Daily" lastn="7">
   <MTEntries>
   ...
   </MTEntries>
   </MTArchiveList>
   

In other words, wrap your <MTEntries>...</MTEntries> in the <MTArchiveList> tag, which has the effect of listing the last 7 days worth of archives--and for each day of archives, then displays all of the entries from that day.

As for the reason why it's a bit hacky to do this: we currently don't support non-consecutive days in <MTEntries> because there isn't a fast way of looking up "the last N days with posts on them". There is a fast way of looking up "the last N days" and "the last N posts", so that is why we have always supported those.

In fact, the method used above is basically just as fast (in terms of system processing) as using a built-in non-consecutive days would be--in either case, the system needs to iterate through the entries in the DB until it finds N days worth of posts (== N daily archives).
kadyellebee
Wow, this is a great solution!  Thanks Mena!  I have several blogs/journals that aren't nearly as used as my main ones, and they will be much happier with this tongue.gif

Have I mentioned lately how much Ben and Mena rock?!  :D

Kristine
tamaracks
I wish there was an offset attribute for MTArchiveList. I love this method, because I think it would make it easier for people to continue reading. My index page is listed in reverse chronological order, since I figure a visitor would want to be able to easily see the last thing I wrote. However, my daily archives are in chronological order, since I think someone going through the archives would want to see them in the order they were written.

I was using the last 5 entries on my index, and then a link to the sixth most recent using an MTEntries tag with offset. However, this seems confusing, because if you were reading down the page and then clicked on the previous link, you would have to read *up* in the page to continue reading. So I thought that it would be nice to have the last 3 days on my index, then a link the fourth most recent day. This way, a reader would start at the top of that day and be able to read down also. I can think of some ways to do this in php, but can anyone think of a way to do it in MT?
girlie
Maybe I'm misunderstanding what you want, but doesn't this work:

CODE
<MTArchiveList archive_type="Daily" lastn="3">
<MTEntries>
(entries code here)
</MTEntries>
<MTArchivePrevious>
<a href="<$MTArchiveLink$>"><$MTArchiveTitle$></a>
</MTArchivePrevious>
</MTArchiveList>


??
tamaracks
The problem with that is it shows up after every day, not just the last one on the index. Maybe I didn't clarify that. smile.gif I was having a hard time describing what I am trying to do.
girlie
From looking at your page, you seem to have it set up in a reasonable way. I see a link at the bottom to the previous day's archives page. How are you generating that link (to where it points to an archive page and not a specific entry on that page)?

Meaning, could you post the MTEntries code you're currently using here (with the CODE buttons).
tamaracks
I'm using PHP. At the end of every entry, I assign an array that holds the information of the previous day for that entry. The variable gets reassigned until it ends up with the previous day of the last entry. Then I use the variable to create the link at the end.

I was just wondering if there was a strictly MT way to do this. PHP works fine for now, however. I just don't particularly like making such little things dynamic.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.