20 Jun, 2004
Today in weeks/months/years past
Posted by: Jennifer In: WordPress Plugins
The idea of this plugin was to create a version of this for WordPress. I am aware that there is another similar script – but I didn't want the actual posts pulled in – just the link to go see the posts for that day in the past. As well – I wanted to use it outside the WP Loop.
Current Version: v 2.0
Last updated: 11/17/04 10:37pm
So here's the plugin – installation and use are pretty simple:
1) Download and install this plugin (right-click save as.. with a .php extension) – upload to your wordpress plugins folder (wp-content/plugins/ ). Activate through the admin interface.
IMPORTANT NOTE ABOUT DOWNLOAD: Make sure you do NOT have any extra spaces after the last ?> in your copy of the file. Extra spaces will give you various "header already sent" type errors.
2) This plugin has the following three functions you can call:
<?php showYearsAgo(); ?>
<?php showWeeksAgo(); ?>
<?php showMonthsAgo(); ?>
All three functions take the following (optional) parameters:
-first parameter (number) is number of years/weeks/months the script should display in history.
default is 3 for years, and 1 for weeks and months.
-second parameter (string – enclose in single quotes) – text/html to show before each link.
-third parameter (string – enclose in single quotes) – text/html to show after each link.
-fourth parameter (boolean – true/false) should it show the date. If so it will display like this:
This day 1 week ago: 06/05/2004
Otherwise it will display just this:
This day 1 week ago
-fifth parameter (string – enclose in single quotes) is only used if the second parameter is true. This is what should be used as the seperator when displaying the date. Default is a slash: /
-sixth parameter (boolean true/false) should it display the titles from that date. Default is false.
-seventh parameter (string – enclose in single quotes) text/html to show before the group of titles. Default is '<ul>'
-eigth parameter (string – enclose in single quotes) text/html to show after the group of titles. Default is '</ul>'
-ninth parameter (string – enclose in single quotes) text/html to show before each title. Default is '<li>'
-tenth parameter (string – enclose in single quotes) text/html to show after each title. Default is '</li>'
So here's an example:
<?php showYearsAgo(2,",'<br />',true,'.'); ?>
If today's date was 3/10/2004 and there WERE posts on these days – it would show the following:
(except instead of the blank link – it will actually go to an archive page with all the posts from that day.
To display the link with the posts from that date (we'll use the showWeeksAgo() and showMonthsAgo() functions):
showWeeksAgo('1', '<li>', '</li>', true, '/', true, '<ul>', '</ul>', '<li>', '</li>');
showMonthsAgo('3', '<li>', '</li>', true, '/', true, '<ul>', '</ul>', '<li>', '</li>');
I'm sure some people may want to change the way the date is displayed (ie. day first then month then year, or something else…) – to do that you can just modify one line. Look for the variable $forDisplay in each function. That is the one that will display the date.
Current Ver: v 2.0
new in v. 2.0
Added support for up2date plugin
Many updates thanks to JABecker:
Added ability to display post title(s) from archive page, cleaned up some code, added before after group and title code
new in v. 1.1
Bug fix error when not displaying date.
new in v 1.0
Fixed MAJOR bugs with showWeeksAgo and showMonthsAgo. – logic was breaking.