Combining lastn and days in <MTEntries>

Published on November 1, 2005 at 8:17 PM EST
In the Tutorials category.

An exquisite, new combination of two different treats.

The <MTEntries> container tag has two often-used attributes: lastn and days. The lastn attribute will display the x most recent entries (regardless of whether they all occur on one day or 10 days, for example). The days attribute will display whatever entries occur in the last x days (regardless of whether there are 0 or 18 entries in that timeframe, for example). Each of these options is mutually exclusive, meaning they can’t be used together. Or can they? A little PHP does the job!

Why would you want to combine these two attributes? Different display and entry listing options: show the 7 most recent entries, displaying a larger excerpt of any entry in the last 2 days.

This is actually a simpler variation on Cookie Publishing.

As I mentioned, PHP is required to implement this. Note the lastn and $days values below (bolded)—change them to suit your needs. This code is most likely useful on your Main Index, but I’m also using similar code here for the Menu at the right.

<MTEntries lastn="15">


   <?php $days = 2;
   $entrydate = mktime(<MTEntryDate format="%H, %M, %S, intval('%m'), %e, %Y">);
   $now = time() - 60 * 60 * 24 * $days;
   if ($entrydate >= $now) { ?>

      <li><a href="<MTEntryPermalink>"><MTEntryTitle></a><br />

   <?php } else { ?>
      <li><a href="<MTEntryPermalink>"><MTEntryTitle></a></li>
   <?php } ?>


Of course, you don’t need to use this in an unordered list. Add your own HTML and CSS to better suit your needs!