scriptygoddess

20 May, 2003

"Blog last Updated…" for non-blog-only sites

Posted by: Jennifer In: Scripts

On sites where the homepage is not the main page of the blog, it isn't always easy to tell when the last update was, and for those of us whose sites are built that way, it can sometimes be a pain to keep the "Last Updated: #########" line up to date. I realized a while back that since I generally write a blog entry of the "hey I added something to {link}this page{/link}" sort even when my updates weren't directly blog content related, so I built this little PHP script that keeps my last updated tag correct without my even thinking about it, since it gets it from the most recent blog entry and pastes it into any page on my site. I use Greymatter, but I don't think it would be too hard to modify this to any other blog program.

First you get the entrylist from greymatter as an array (each entry is on a seperate line of the file, and becomes a seperate array item). Be sure to change the line below to your server path.

$entry_List = file ('/server/path/to/your/gm-entrylist.cgi');

Greymatter inserts the data for each new entry at the beginning of the file, so the most recent entry will be the first line of the file

$last_Entry = $entry_List[0];

The information in that line will be entry number, author, entry title, date/time, etc seperated by pipes (that's this character: | ), and we only need the date for this, so we turn that line into an array, splitting on the |s.

$entry_Paramaters = explode ("|", $last_Entry);

The date is the fourth piece of data (but arrays start counting at 0) so:

$entry_Date = $entry_Paramaters[3];

Then we split again to seperate the date into day month and year. This time split on the / because Greymatter keeps the date as mm/dd/yy (you don't have to do the rest if you want to keep the date in that format, you could just echo it here, but I wanted to be able to change it)

$date_elements = explode("/" ,$entry_Date);

Then we turn those pieces into a timestamp so we can use it.

$mytimestamp = mktime (0, 0,0 ,$date_elements [0], $date_elements[ 1],$date_elements [2]);

And spit the date out formatted however we like using the date function of PHP.

PHP date formating:
a – "am" or "pm"
A – "AM" or "PM"
d – day of the month, 2 digits with leading zeros; i.e. "01" to "31"
D – day of the week, textual, 3 letters; i.e. "Fri"
F – month, textual, long; i.e. "January"
h – hour, 12-hour format; i.e. "01" to "12"
H – hour, 24-hour format; i.e. "00" to "23"
g – hour, 12-hour format without leading zeros; i.e. "1" to "12"
G – hour, 24-hour format without leading zeros; i.e. "0" to "23"
i – minutes; i.e. "00" to "59"
j – day of the month without leading zeros; i.e. "1" to "31"
l (lowercase 'L') – day of the week, textual, long; i.e. "Friday"
L – boolean for whether it is a leap year; i.e. "0" or "1"
m – month; i.e. "01" to "12"
n – month without leading zeros; i.e. "1" to "12"
M – month, textual, 3 letters; i.e. "Jan"
s – seconds; i.e. "00" to "59"
S – English ordinal suffix, textual, 2 characters; i.e. "th", "nd"
t – number of days in the given month; i.e. "28" to "31"
U – seconds since the epoch
w – day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday)
Y – year, 4 digits; i.e. "1999"
y – year, 2 digits; i.e. "99"
z – day of the year; i.e. "0" to "365"
Z – timezone offset in seconds (i.e. "-43200" to "43200")

I wanted mine formatted like "January 1, 2003" so I used:

echo "Last Updated: ";
echo date (" F j, Y", "$mytimestamp");

Here's just the code, without the explination (don't forget to change the server path, and date format):

$entry_List = file ('/server/path/to/your/gm-entrylist.cgi');
$last_Entry = $entry_List[0];
$entry_Paramaters = explode ("|", $last_Entry);
$entry_Date = $entry_Paramaters[3];
$date_elements = explode("/" ,$entry_Date);
$mytimestamp = mktime (0, 0,0 ,$date_elements [0], $date_elements[ 1],$date_elements [2]);
echo "Last Updated: ";
echo date (" F j, Y", "$mytimestamp");

1 Response to ""Blog last Updated…" for non-blog-only sites"

1 | Michael Hanscom

May 22nd, 2003 at 2:54 am

Avatar

Another possible solution (not incidentally in the least, the one that I use on my main page 😉 ) is simply to create an index template with the excerpts of the last X entries stripped of HTML, and use an include to put that into the main page.

Of course, it all depends heavily on your particular layout, but it works well for me.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements