MovableBlog: Archives: PHP Hypertext Preprocessor

A weblog about the Movable Type Publishing Platform and other geekery

November 30th, 2004

Related del.icio.us Links in Your Sidebar Using RSS, PHP and Magpie »

del.icio.us, for me, is not so much a way to store my bookmarks online and view others' bookmarks as it is a collaborative linkblogging tool. In this article, I detail how I created a "related links" sidebar on my personal weblog, Just a Gwai Lo (scroll down to the "Delicious" heading; the same script is used to generate a less-cluttered page of del.icio.us links). Here is, in brief, how it works: I make a link at del.icio.us, tag it—generally looking at the HTML pages of the tags I'm using, to see what I'm getting myself into—and then use the RSS feeds generated for each tag to add on a few links as, essentially, related links. If Flickr had tags inside a <dc:subject> element like del.icio.us did, I'd be spending the time writing this article making basically the same thing, except a "related photos" page. I suppose I could learn the APIs for both del.icio.us and Flickr and accomplish the same thing, but I'd rather not.

The first two lines of the script enable the RSS fetching functions from the Magpie RSS library. The line after that starts an unordered list for the links. If you'd rather skip reading the explanation in this article, you can view the source code. One day I'll put this code in my Subversion repository, which gently weeps because it is currently empty.

I should mention that the source code is the most current version of the script, and may differ slightly from what you read below.

You need the Magpie PHP RSS library. Also make sure to make the changes noted in the del.icio.us script itself.

require_once "/home/richard/rssclasses/rss_fetch.inc";
require_once "/home/richard/rssclasses/rss_utils.inc";

print "<ul>\n";

The third line tells the rest of the script what your username is:

$username = "username"; // replace with your del.icio.us username

When I was testing the script, del.icio.us was down for a few minutes, and I needed the ability to say the del.icio.us links were "unavailable at the moment". The Magpie Cookbook gives a method for cloaking warnings, so I included the following line before Magpie fetched the RSS feed.

error_reporting(E_ERROR); // cloak error messages

The next line fetches the RSS feed and puts the items into an an object.

$del = fetch_rss("http://del.icio.us/rss/".$username);

The next line simply checks to see whether the fetch was successful:

if ($del) {

Since del.icio.us shows the last 30 links that you've posted, it can get a little out of hand when you have related links on top of that, so I limit the amount of links to 5. You can experiment with the number to get the amount you're commfortable displaying.

$delitems = array_slice($del->items, 0, 5);

Starting the loop to display the items from the RSS feed:

foreach ($delitems as $item) {

The next line and following if block check to see if the date has been printed yet. If you want a different date format than, for example, "November 21st, 2004", check the PHP date codes and replace "F jS, Y" accordingly.

   $datethis = date("F jS, Y", parse_w3cdtf($item['dc']['date']));    
if ($datethis != $dateprinted) {
print " <li>";
print $datethis;
print "</li>\n";
}

Now comes the code to display your link and the description, if there is one. I like having lots of print statements because it makes debugging easier.

   print "  <li>";
print "<a href=\"";
print $item['link'];
print "\">";
print $item['title'];
print "</a>";
if ($item['description'] != "") {
print ": ";
print $item['description'];
}
print "</li>\n";

Now the fun part. The next if statement checks to see if there is a <dc:subject> element inside the item that the script is processing, which means you have tagged the link with one or more tags.

   if (isset($item['dc']['subject'])) {

If there are tags, then the script converts the string separated by spaces into an array.

     $tags = explode(" ", $item['dc']['subject']);

Now the script creates another list item in HTML, then starts a nested list within that list item.

     print "  <li>\n";
print " <ul>\n";

After starting the nested list, the script fetches the RSS feed for each of the tags in the item. The third line in thiis code block limits the related items to 2, because otherwise, if you tag your item with a lot of tags, you'll get a lot of related items.

     foreach ($tags as $tag) {
$tagrss = fetch_rss("http://del.icio.us/rss/tag/".$tag);
$tagitems = array_slice($tagrss->items, 0, 2);

Still only processing the RSS feed of one of your tags, another loop starts to process the items in that RSS feed. The second line filters out del.icio.us links created by you (after all, those links appear in the RSS feed for the tag as well) because it would just be redundant, especially if the last few links with that tag were your links.

       foreach ($tagitems as $tagitem) {
if ($tagitem['dc']['creator'] != $username) {
print " <li>";
print "<a href=\"";
print $tagitem['link'];
print "\">";
print $tagitem['title'];
print "</a>";

We're still in the second loop (that is, inside the loop for the tag's RSS feed which is inside the loop for processing the tags of your original item), and the following block...

           if (rtrim($tagitem['description']) != "") {
print ": ";
print $tagitem['description'];
}

Because you were not the original author of the related link--unless you have another del.icio.us account that you linked something using the same tag with--you can absolve yourself of some responsibility of the content (link URL, text and description) by saying who it was linked by. In this script, I had it so that it linked to the author's del.icio.us page. (It seemed only fair that if I'm syndicating their content I should link to the page from which it came.) After doing this, all the loops, except for the very first, which is of your links' RSS feed, are closed, as is the nested list.

           print " (linked by ";
print "<a href=\"http://del.icio.us/";
print $tagitem['dc']['creator'];
print "\">";
print $tagitem['dc']['creator'];
print "</a>)</li>\n";
}
}
}
print " </ul>\n";
print " </li>\n";
}


The next line stores the date of the most recent item printed, so that when it goes back to the top of the loop, it can check against the date of the next item. The original loop is closed (after all of your items are processed) and the if block is closed.

   $dateprinted = $datethis;
}
}

Remember how we had the rudimentary error checking at the beginning? The following else block just prints something more friendly than an ungly error message. Lastly, the end tag for the unordered list is printed.

else {
print "<li>del.icio.us links not available at the moment.</li>\n";
}

print "</ul>";

That's the script. Let me know if you run into any problems with it. I've been meaning to update my instructions to integrate PHP and del.icio.us using Magpie and my instructions to integrate del.icio.us using a Movable Type plugin, but instead wrote the above script.

Posted by Richard at 11:01 PM

September 1st, 2004

Bryght »

Like Roland, Boris, James and Adrian, I am a Bryght Guy. Bryght will promote the open source CMS Drupal, develop custom instances of and offer mass hosting and consulting services for the software and CivicSpace, and support the Drupal community. I have a 4-word title, which I feel the need to point out, but I'll deny any accusation of being a developer or decision-maker for the company. James Walker and Adrian Roussow are the developers, and fellow Vancouverites Roland Tanglao is the Chief Blogging Officer (!) and Boris Mann is the Drupal Kool-Aid keeper, so to speak. The only person I speak for on my sites is myself. That said, I now have a corporate weblog, which I will try to syndicate here and elsewhere.

I met Roland for the first time in January of this year. He knew me because of MovableBlog but also because of the now defunct Vancouver Webloggers site as well as the other blogging exploits too numerous to mention. I met Boris some time before April of this year, but long story short, my weblogs got me noticed and helped in getting my new job, but I hear that's de rigeur these days.

Supporting Drupal does not mean I'm giving up on Movable Type. 3.1 adds really great features that makes it worth buying, and Six Apart has made a commitment to the people who develop around it, and I do not expect that commitment to waver. That said, anything I say about Drupal or Movable Type or even Wordpress (I use all three daily) as well as the companies and people behind them should be considered alongside the company I work for. Since it's a market, there is of course competition involved, but history will show that this is the golden age of blogging and blogging software, and I'm glad to be a small part of it.

Posted by Richard at 05:38 PM

April 16th, 2004

Integrating del.icio.us with PHP and Magpie »

In December of last year I published a way to integrate into your Movable Type-powered weblog. If you have PHP installed on your system, you can use the Magpie RSS PHP library in conjunction with the following PHP code to integrate del.icio.us on any website that has PHP. You will need to replace every instance of username with the del.icio.us links you wish to syndicate.

<h4><a href="http://del.icio.us/username">del.ico.us</a> links</h4>
<ul>
<?php

require_once "rss_fetch.inc";
// change to reflect path of rss_fetch.inc

$yummy = fetch_rss("http://del.icio.us/rss/username");

$maxitems = 15;

$yummyitems = array_slice($yummy->items, 0, $maxitems);

foreach ($yummyitems as $yummyitem) {

print '<li>';
print '<a href="';
print $yummyitem['link'];
print '">';
print $yummyitem['title'];
print '</a>';
if (isset($yummyitem['description'])) {

print ': ';
print $yummyitem['description'];

}
print '</li>';
print "\n";

}

?>
</ul>

Posted by Richard at 02:13 PM | TrackBacks (23)

May 16th, 2003

Plural Comments »

Jesper has developed MTPlural [more info] [MT support thread] which will not only add an 's' to the end of your, but allows for alternate comments link text depending on whether there are a) no comments; b) one comment; or c) multiple comments.

For those that think doing this dynamically is a better idea (and it's not), here's the PHP code I use at China Weblog:

<MTEntryIfAllowComments>
<p><a href="<$MTEntryPermalink$>#comments"><?php

if (<$MTEntryCommentCount$>) {
print("<$MTEntryCommentCount$> comment");
if (<$MTEntryCommentCount$> > 1) print ("s");
}
else {
print("Comment");
}

?></a></p></MTEntryIfAllowComments>

The plugin idea is a better one, since it cuts down on the processing the back-end needs to do each time a person visits your site.

Thanks to Paulo for the fodder heads-up.

Posted by Richard at 02:52 PM | TrackBacks (0) | Comments (0)

March 31st, 2003

Redirecting to New Archive Pages With .htaccess »

Jim Ray: Movable Type file rewrite. This seems like a better solution than my own (not yet implemented): replacing each individual template file with a PHP header() redirect, and the (temporary) Individual Entry Template was going to look something like this (depending on the format of URL I wanted of course):

<?php

header ("Location: <$MTBlogArchiveURL$><$MTEntryCategory dirify="1"$>/<$MTEntryTitle dirify="1"$>.php");

?>

But using one file (i.e. .htaccess) seems a lot more efficient.

Posted by Richard at 01:21 PM | TrackBacks (0) | Comments (0)

March 30th, 2003

Late Night Links »

Posted by Richard at 02:30 AM | Comments (0)

March 15th, 2003

MT Archives Indicator »

As for the code that I use for the archives indicator (click on a monthly archive in the sidebar and it not only disables the link for the archive, but changes the background colour of the text), here it is.

<p><b>Archives</b><br />

<MTArchiveList archive_type="Monthly">
<?php

if (!eregi("<$MTArchiveDate format="%Y_%m"$>", $_SERVER['PHP_SELF']))
print "<a href=\"<$MTArchiveLink$>\"><$MTArchiveTitle$></a>";
else print "<span class=\"greyback\"><$MTArchiveTitle$></span>";

?><br />
</MTArchiveList>
</p>

It exists on every page with a sidebar (with a few exceptions) because the above code is in a Template Module called "Archives Listing". I then put <$MTInclude module="Archives Listing"$> in where the sidebar appears in my regular (i.e. Index, Individual and Monthly) templates.

In your CSS, you will need something like this:

.greyback
{
background-color: #CCCCCC;
}

Of course, you can chose any colour you want, with an appropriate CSS class name.

Posted by Richard at 01:36 PM | TrackBacks (0) | Comments (0)

February 22nd, 2003

Cleared Bookmarks II »

A few more articles cleared out of my Bookmarks.

Posted by Richard at 10:18 PM | Comments (0)

Cleared Bookmarks »

I needed to clear some bookmarks, and here are the geekier of the articles that were there.

Posted by Richard at 10:09 AM | Comments (0)

February 19th, 2003

Custom Error Pages with PHP and Apache »

Custom Error Pages with PHP and Apache: I thought the first bit of code was inspired, but then the author gets into dynamically generating content based on the URL, and even gives code for a smart URL redirect la PHP.net, both using error documents.

Posted by Richard at 08:55 PM | Comments (0)

December 11th, 2002

TrackBack Form in PHP »

The form which pings the sidebar (which actually a post with, in my example, the TrackBack ID of 1) was created with —you guessed it—PHP.

Here's the form. Nothing new here if you're experienced with HTML.

<form action="post.php" method="GET">

<div align="center">
<input type="hidden" name="tb_id" value="1">
<input type="hidden" name="form" value="1">
<table><tr>
<td align="right">
<p>Blog Name</p>
</td>
<td>
<input type="text" name="blog_name" size="35"
value="">
</td>
</tr>
<tr>
<td align="right">
<p>Post Title</p>
</td>
<td>
<input type="text" name="title" size="35" value="">
</td>
</tr>
<tr>
<td align="right">
<p>Excerpt</p>
</td>
<td>
<input type="text" name="excerpt" size="60"
maxlength="150" value="">
</td>
</tr>
<tr>
<td align="right">
<p>Permalink</p>
</td>
<td>
<input type="text" name="url" size="60" value="">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="submit" name="submit">
</td>
</tr>
</table>
</div>
</form>

Here's the PHP file, post.php, which the form calls:

<?php

$data="form=1&tb_id=1&blog_name=$blogname&title=$title
&excerpt=$excerpt&url=".urlencode($url);
$http_response="";
$fp=fsockopen("www.yourhost.com", 80);
fputs($fp, "POST /mt/mt-tb.cgi HTTP/1.1\r\n");
fputs($fp, "Host: www.yourhost.com\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: " . strlen($data) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, "$data");
while(!feof($fp))
{
$http_response.=fgets($fp, 128);
}
fclose($fp);
list($http_headers, $http_content)=explode("\r\n\r\n", $http_response);
header("Location: http://www.yourblogURL.com/");

?>

Replace www.yourhost.com and www.yourblogURL as necessary, and make sure the line after the first appearance of www.yourhost.com points to the right location of mt-tb.cgi.

Don't ask me to translate it. I grabbed it from a PHP newsgroup. It works for me, except I still can't figure out how to get just the pings from TrackBack ID 1 on the sidebar, rather than all pings, which is currently the case. What I really should have done in the first place is have it ping a TrackBack category.

Posted by Richard at 11:46 PM | TrackBacks (2) | Comments (0)

December 7th, 2002

Ordinal Numbers with MT and PHP »

A subtle change to the date headers here at MovableBLOG. There are now "st" after any date with the day of the month being 1 or 21, "nd" after the days of the month 2 and 22, "rd" after days of the month 3 and 23, as well as "th" for any other day of the month. I didn't find a solution in the MT manual, but it apppears there is a plugin which can convert dates in to ordinal numbers.

It probably would have done me some good to look in the MT forums, since a solution was already posted by billzeller. But since I took the time to code it myself, I might as well publish it:

<?php

$dateToday = <$MTEntryDate format="%e"$>;
switch ($dateToday)
{
case 1:
case 21:
case 31:
$dayEnding = "st";
break;
case 2:
case 22:
$dayEnding = "nd";
break;

case 3:
case 23:
$dayEnding = "rd";
break;

default:
$dayEnding = "th";
break;
}

print "<$MTEntryDate format="%B %e"$>".$dayEnding.", <$MTEntryDate format="%Y"$>";

?>

Play around with that last print statement to get the desired date format.

Posted by Richard at 01:08 AM | TrackBacks (0) | Comments (0)

December 4th, 2002

Links Divided Over 2 Columns »

On the Vancouver Webloggers links page, the links are alphabetized and divided into a two columns. But how?!

With PHP of course.

Place in your index template somewhere this code. I have a whole blog in MT dedicated to links, and in the case of Vancouver Webloggers, use the category "Other" for bloggers other than the authors of the site.

<?php

$links = array();

<MTEntries category="Other" sort_order="ascend" sort_by="title">
$links[] = "<$MTEntryBody encode_php="qq"$>";
</MTEntries>

$numlinks= count($links);

?>

Then, where you want the links to appear in two columns, insert this code:

<table>

<tr>
<td>
<?php
$half = $numlinks/2;
$half = (int) $half;

for ($i = 0;$i < $half; $i++)
{
print $links[$i]."<br />\n";
}
?></td>

<td><?php
for ($y = $half; $y < $numlinks;$y++)
{
print $links[$y]."<br />\n";
}
?>
</td>

</tr>
</table>

Note that for the title of each link's entry, I take the blog name and capitalize the first letter. Also, I follow the practice of not using "A" or "The" as the first word in the title. So "The Blog That Never Was" is inserted in the the title as "Blog That Never Was, The" and "a blog through time" becomes "Blog through time, A".

Posted by Richard at 12:07 AM | TrackBacks (0) | Comments (1)

November 7th, 2002

Selecting Text Problems in IE 6? »

This is off-topic as far as Movable Type is concerned, but if you're having problems selecting text from your site in Internet Explorer 6, add this code to the first line of your code:

<?xml version="1.0" encoding="iso-8859-1"?>

If it gives you a PHP error, add this line instead:

<?php print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; ?>

I found this here after searching Google Groups forever, giving up, and trying websites instead.

It works for me (over at China Weblog). Added bonus: it still validates XHTML Transitional 1.0.

Posted by Richard at 01:08 AM | TrackBacks (1) | Comments (8)

October 12th, 2002

2 Rows of 14 »

Someone wanted to know how to have two rows of 14 days (it ends up being 3 rows) on their MT blog's calendar, and I came up with a PHP solution.

Posted by Richard at 01:37 AM | TrackBacks (0) | Comments (0)

July 20th, 2002

Tape Delay »

Ever write something, but realize after sleeping on it, that you made a horrible mistake? Well, I have, so the personal blog, which is currently on hiatus (but returning soon), will have what I'm calling a "tape delay".

You know how some live broadcast events are delayed? I remember that some Monday Night Football games are tape delayed by about an hour to get the biggest audience possible, and that Howard Stern, when he was being broadcast in Canada, was tape delayed by a few seconds to give radio stations here a chance to censor anything inappropriate (which, apparently, was often).

So...

Put this code somewhere near the beginning of your index template.

<?php

$now = time();

// for me, the above code is $now = time() - (3*60*60);
// because my host is on Eastern Time, whereas I'm on
// Pacific Time

$twentyFourHRs = 24 * 60 * 60;

// change the 24 to whatever number of hours you
// want to delay a post for.

?>

Then, when you get to the point of your <MTEntries>, insert this code:

<MTEntries>

<?php

// the following if statement should be entered
// without line break, to make things easier for
// some reason, I forget why

if ( ($now - mktime(<$MTEntryDate format="%k, %M, %S, %m, %e, %Y"$>)) > $twentyFourHRs)

{
?>
<i>YOUR MT TAGS</i>
<?php

}
?>

</MTEntries>

This has uses as a bare-bones editing tool for group weblogs, or even for comment systems (maybe) too. If someone posts something that you don't approve of, and don't want a lucky few who continuously press Refresh to see what they wrote, you could put it on "tape delay".

This is a early release of code of something that I'd like to have password override (for proofreading and making sure the HTML code is right) and maybe a more full-fledged moderating system for group blogs and comments, unless that's planned for a future release of MT *hint hint*. Also, similar code would necessarily need to be added for archives, but I'm planning on going without archives for a while after returning.

Posted by Richard at 11:45 PM | Comments (4)

July 18th, 2002

Better way to highlight most recently added? »

Is there a better way to highlight the most recently added entries in an alphabetically sorted (or any way other than by time) than what I cobbled together at this ungodly hour?

<?php $last_five = array(); <MTEntries lastn="5"> $last_five[] = <$MTEntryID$>; </MTEntries> ?>

<MTCategories>
<MTEntries sort_by="title" sort_order="ascend">

<?php
if (in_array(<$MTEntryID$>, $last_five))
{
?>
<b><$MTEntryBody$></b><br />
<?php
}
else
{ ?>
<$MTEntryBody$><br />
<?php
}
?>

</MTEntries>
</MTCategories>

For an example, see the sidebar here.

A plugin, with a tag like something like <MTIfMostRecent lastn="n"> etc., would be way preferable to using PHP (not that I don't like PHP!).

Posted by Richard at 02:53 AM | Comments (1)

June 19th, 2002

no_generate attribute »

Ben reveals another undocumented feature: no_generate attribute for <MTEntryExcerpt$>.

This is useful for when you want to have an excerpt of your choosing but, when you don't write one in yourself, nothing shows up. Or, you could test to see if there is an excerpt using PHP, and print a message like "No Excerpt." if there's no excerpt.

<MTEntries lastn="1">
<?php

$excerpt = "<$MTEntryExcerpt no_generate="1"$>";
if ($excerpt)
{
print $excerpt;
}
else
{
print "No Excerpt.";
}

?>
</MTEntries>

Posted by Richard at 01:39 AM | Comments (0)

May 30th, 2002

Sliding Menu powered by MT »

This requires PHP (or the ability to do SSI includes) on your server as well as Javascript enabled on the client's browser.

I have it set up as two blogs in MT, one for the links, and one for the blog content.

In the blog content's main index, between the <head> tags, insert this Javascript code:

<script type="text/javascript">
function toggleMenu(currMenu) {
if (document.getElementById) {
thisMenu = document.getElementById(currMenu).style
if (thisMenu.display == "block") { thisMenu.display = "none"
}
else { thisMenu.display = "block" }
return false
}
else { return true }
}
</script>

And the CSS, also between the <head> tags, for the menu looks like this:

<style>
.menu { border-left: 1px #FFFF00 solid;
padding-left: 2px;
display: none; margin-left: 15px; }
<style>

Modify the color in the menu as required.

Just to repeat, all that code was in the main index file of the main blog.

Then create another blog in MT, which will contain the links in your sidebar or wherever you want the menu. Delete all the templates and turn off archiving. Then create a new index template. For mine, I used the filename resources.html. You can choose what you want. (Note that I have the same blog directories as in the main blog.)

The resources.html template in the second blog looks like this:

<MTCategories>
<a href="" onMouseOver="(window.status='toggle
listing');
return true;" onMouseout="window.status=' '"
onClick="return toggleMenu('<$MTCategoryLabel dirify="1"$>')"><u><b><$MTCategoryLabel$></b></u></a>
<br />
<span class="menu" id="<$MTCategoryLabel dirify="1"$>">
<MTEntries sort_by="title" sort_order="descend">
<$MTEntryBody$><br />
</MTEntries>
</span>
</MTCategories>

Every time you want to add a link, the "Main Entry Text" is a simple HTML URL, e.g.:

<a href="http://www.cnn.com/">CNN</a>

Each heading in the menu is an MT category, so make sure you categorize the entry before publishing it.

Now go back to the main blog and insert the following code where you want the menu to appear:

<?php include("resources.html"); ?>

If you don't have PHP but can do SSI includes, then use the following code:

<!--#include virtual="resources.html"-->

(Javascript code taken from JavaScript for the World Wide Web by Tom Negrino and Dori Smith, pp. 290-1)

Posted by Richard at 02:34 PM | Comments (2)

May 13th, 2002

Exclude a Single Category »

I worked on this for about a half-hour and it actually worked.

Might noticeably slow down your site, because there's PHP for each entry.

Note: there are still some bugs to work out. Like how the date header doesn't show up if the excluded category is the latest post.

<MTEntries>
<?php

$category_array = array();
<MTEntryCategories>
$category_array[] = "<$MTCategoryLabel$>";
$count++;

</MTEntryCategories>
$flagged = FALSE;
for ($i = 0; $i < $count; $i++)
{
if ($category_array[$i] == "CATEGORY_NAME")
{ $flagged = TRUE;
}
}

if (!$flagged)
{
?>

[insert MT code and HTML here; this will only get shown on your site if CATEGORY_NAME is not one of the categories for the individual entry]

<?php
}

reset($category_array);

?>

</MTEntries>

Posted by Richard at 01:25 PM | Comments (3)

April 28th, 2002

Multiple Categories Tip »

Using MT, some Javascript and PHP, and a lot of duct tape, I've created a multiple category listing that floats over a blog and closes itself when the category is clicked. There's also a "Close Window" option, if curiosity-seekers just want to see which category a post belongs to.

Things necessary for this to work: Movable Type 2.0 (does not work with previous versions!); PHP on your server; Javascript enabled on the client's browser, and a little patience to work the bugs out. It's...well, it's a little complicated.

Posted by Richard at 02:12 AM | Comments (0)

April 13th, 2002

Less than N Days »

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 06:05 PM | Comments (0)