MovableBlog: Less than N Days

Nuance 2.0

April 13, 2002

As an addendum to the monthly tags post, there's another component of the Recently quasi-blog that was a little tricky at first. I wanted a way to show that another blog had been updated within n days. The way I did this was with some MT and PHP magic.

I created an index template that looks something like this (the filename in my case is dateoflastentry.php):

(the code for the timestamp was derived from this example)

<?php function makeTimeStamp($year,$month,$day) { return mktime(0,0,0,$month,$day,$year); } <MTEntries lastn="1"> $startDate = makeTimeStamp (<$MTEntryDate format="%Y"$>, <$MTEntryDate format="%m"$>, <$MTEntryDate format="%d"$></MTEntries>); ?>

The code that I have looks like this:

<?php

function lessThanNDays($timestamp)
{
$now = time();
$betweenTodayAndLastN = $now - $timestamp;
$nDays = 3;

$nDaysAgo = 60 * 60 * 24 * $nDays;

if ($betweenTodayAndLastN < $nDaysAgo)
{
return TRUE;
}
else
{
return FALSE;
}
}

include("recemment/dateoflastentry.php");
if(lessThanNDays($startDate))
{
print("<b>Recently</b>");
}
else
{
print("Recently");
}
?>

The include statement is in bold. Note that it appears in a different directory than the main blog, but just because that's where the Recently blog appears.

The $nDays variable in the lessThanNDays function is set to 3, so that any blog entry with a timestamp of less than 3 days ago results in "Recently" appearing in bold. Not the most elegant way to do it. But it does work!

See also this post in Tips & Tricks.

Posted by Richard at 6:04