MovableBlog: Less than N Days
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)
The code that I have looks like this:
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.