Some of you have been blogging or journaling for years and have seen other people do links at the bottom or side of their entries to "One Year Ago today" or "Two Years Ago today" or whatever. Most times, these links are hand-coded. Here is a way to automatically pull these links in using PHP and Moveable Type.
Let me start off by saying that this script was thought up by Amy over at domesticat.net for Greymatter. I simply modified it and expanded it for use in Moveable Type. Notes below will detail the changes and modifications I made.
You can see an example of how I have it setup to work over on this entry in my journal.
What this script essentially does is search a file for all entries made on the same date in previous years. So first, we'll need to make a new index file in MT that contains the information we'll later search.
Copy and paste this code exactly as it appears into a new index template. Be careful not to add any additional linebreaks or spaces, as it will break the script. Have it output to a file called entrylist.inc
What does that all mean? Glad you asked. Here's the content broken into colors, followed by an explanation:
<MTArchiveList><MTEntries><$MTEntryLink$>|<$MTEntryAuthor$>|<$MTEntryCategory$>|<$MTEntryDate format="%m/%d/%Y"$>|<$MTEntryTitle$>|<$MTEntryExcerpt$>
</MTEntries></MTArchiveList>
<MTArchiveList><MTEntries> … </MTEntries></MTArchiveList> – these are just the MT tags to make the list.
<$MTEntryLink$> – this will be replaced with the link to each entry.
<$MTEntryAuthor$> – the author of each entry.
<$MTEntryCategory$> – category of each entry.
<$MTEntryDate format="%m/%d/%Y"$> – This is what will be used to search for entries on previous dates. You can format the display dates to your liking later on, so leave this as it is.
<$MTEntryTitle$> – Title of each entry
<$MTEntryExcerpt$> – excerpt of each entry. If you use the excerpt field for something else in your entries, you can replace this with something like the following:
<$MTEntryBody convert_breaks="0" remove_html="1" trim_to="100"$>
This one is important:
| – This character is known as a "pipe" and is what the PHP script uses to pull apart all the information on each line so you can use each piece individually.
For example, the above code would output something like this, which is my entrylist.inc. Each line contains all the information for that particular entry. The php code will use character returns the separate each line into one entry and then it uses the pipe to separate each piece of information on that line to use later on.
Enough of that mumbo-jumbo. Here's the 2nd part of the script:
Copy this file into notepad or a text editor. Name it today.php and then make the following changes:
# What's the full server path to your entrylist file?
$entrylist = "/path/to/entrylist.inc";
Change this to your server path. For example, it might be:
/home/username/public_html/blogfolder/entrylist.inc
If you don't know the server path, check with your host.
# How do you want the months to be displayed? Edit the text between the
# quotes, but don't put in line breaks. Let the line wrap.
$month_names=array("01.", "02.", "03.", "04.", "05.", "06.", "07.", "08.", "09.", "10.", "11.", "12.");
Replace anything inside the quotation marks with how you want your months to display. "01." can be changed to "January", "Jan", "01", etc. Follow through with the rest of them.
echo "<a href= \"$entry_link \">$year: $subject</a><br/>$excerpt<br/>"
There are more detailed instructions above this line explaining what to do with it. You can format how you want your links to appear here. You can use the following variables:
$month, $day, $year, $subject, $author, $category
My suggestion would be to leave the code as it is the first time you try it out (making sure to change the path to the entrylist.inc) and then once you see what it does, go back and change it to suit your needs.
The last step in this is to include today.php in your Individual Entry Template and include variables to let the script know what day, month and year it is. Place this code in your Individual Entry Template wherever you'd like the links to appear:
<?
$this_month = "<$MTEntryDate format="%m"$>";
$this_day = "<$MTEntryDate format="%d"$>";
$this_year ="<$MTEntryDate format="%Y"$>";
include("/path/to/today.php");
?>
Make sure to change the bolded line to reflect the path to your today.php file.
Please let me know if there are any questions, as I've never been the best at explaining technical things.
——–
footnote: As mentioned, Amy wrote the original script for GM which can be found here. The original script pulls up all entries matching the date, regardless of year (same year entries are included). If this effect is prefered, you can modify the script to remove the following bit:
&& ($date_array[2] < $this_year)
Be aware this will include the CURRENT entry as well as any other entries posted on that day or that day in previous years.
The original script also had no way of including the excerpt, as GM stores that info separately. I modified this to include the excerpt.
The original script had a few bits of information that was needed for GM to process the script (like figuring out the four digit year based on the two digit year date) that I removed as it was not needed.