/*
Plugin Name: todayAgo
Version: v 2.0
Plugin URI: http://www.scriptygoddess.com/archives/2004/06/20/today-in-weeksmonthsyears-past/
Description: Gives a link to posts 1 - n? years/months/weeks ago
Author: Jennifer (Scriptygoddess) w/ updates by JABecker (persistentillusion.com)
Author URI: http://scriptygoddess.com & http://www.persistentillusion.com
*/
/*
This plugin has the following three functions you can call:
showYearsAgo();
showWeeksAgo();
showMonthsAgo();
*/
/*
up2date support
*/
if( function_exists( 'u2d_register_plugin' ) ) {
u2d_register_plugin( "Today Ago", "http://www.scriptygoddess.com/up2date/todayAgo.txt", "2.0", 3);
}
/*
11-06-2004
JABecker (mom) changes:
Fixed bugs in showMonthsAgo:
moved adding leading zero to day before for loop
remove unnecessary while loop from check for $getmonth <= 0 Added ability to list post titles under the archive link:
Added $showTitle parameter to show post titles under link to archive page
Added code to display the post title between the tag of the link and the ".after"
Added before/after title and before/after title group parameters */
function showYearsAgo($showyears='3', $before = '', $after='', $showDate=true, $dateSeparator='/', $showTitle=false, $beforeTitleGroup='
', $beforeTitle='', $afterTitle='') {
global $wpdb, $tableposts;
if (!isset($tableposts))
$tableposts = $wpdb->posts;
$today = getdate();
$this_month = $today['mon'];
$this_day = $today['mday'];
$this_year = $today['year'];
if ($this_month < 10) {
$this_month = "0".$this_month;
}
if ($this_day < 10) {
$this_day = "0".$this_day;
}
$info = get_bloginfo('url');
$info = apply_filters('bloginfo', $info);
$homeurl = convert_chars($info);
for ($i=1; $i <=$showyears; $i++) {
//get a year ago
$getyear = $this_year - $i;
$getdate = $getyear."-".$this_month."-".$this_day;
$forurl = $getyear.$this_month.$this_day;
$forDisplay =
$this_month.$dateSeparator.$this_day.$dateSeparator.$getyear;
if ($i > 1) {
$isPlural = 's';
} else {
$isPlural = '';
}
$past = $wpdb->get_results("SELECT * FROM $tableposts WHERE post_date LIKE '".$getdate." %'");
if ($past) {
echo $before."This day ".$i." year".$isPlural." ago";
if ($showDate) {
echo ": ".$forDisplay;
}
echo "";
if ($showTitle) {
echo ":".$beforeTitleGroup;
foreach ($past as $post) {
$post_title = stripslashes ($post->post_title);
echo $beforeTitle.$post_title.$afterTitle;
}
echo $afterTitleGroup;
}
echo $after;
}
}
}
function showWeeksAgo ($showweeks='1', $before = '', $after='', $showDate=true, $dateSeparator='/', $showTitle=false, $beforeTitleGroup='', $beforeTitle='', $afterTitle='') {
global $wpdb, $tableposts;
if (!isset($tableposts))
$tableposts = $wpdb->posts;
$info = get_bloginfo('url');
$info = apply_filters('bloginfo', $info);
$homeurl = convert_chars($info);
// 3600 = 1 hour
// 86400 = 1 day
// 604800 = 1 week
for ($i=1; $i <=$showweeks; $i++) {
$numOfdaysAgo = 604800 * $i;
$weeksAgoTimeStamp = time() - $numOfdaysAgo;
$today = getdate($weeksAgoTimeStamp);
$this_month = $today['mon'];
$this_day = $today['mday'];
$this_year = $today['year'];
if ($this_month < 10) {
$this_month = "0".$this_month;
}
if ($this_day < 10) {
$this_day = "0".$this_day;
}
$getday = $this_day - $numOfWeeksAgo;
$getdate = $this_year."-".$this_month."-".$this_day;
$forurl = $this_year.$this_month.$this_day;
$forDisplay =
$this_month.$dateSeparator.$this_day.$dateSeparator.$this_year;
if ($i > 1) {
$isPlural = 's';
} else {
$isPlural = '';
}
$past = $wpdb->get_results("SELECT * FROM $tableposts WHERE post_date LIKE '".$getdate." %'");
if ($past) {
echo $before."This day ".$i." week".$isPlural." ago";
if ($showDate) {
echo ": ".$forDisplay;
}
echo "";
if ($showTitle) {
echo ":".$beforeTitleGroup;
foreach ($past as $post) {
$post_title = stripslashes ($post->post_title);
echo
$beforeTitle.$post_title.$afterTitle;
}
echo $afterTitleGroup;
}
}
}
}
function showMonthsAgo ($showmonths='1', $before = '', $after='', $showDate=true, $dateSeparator='/', $showTitle=false, $beforeTitleGroup='', $beforeTitle='', $afterTitle='') {
global $wpdb, $tableposts;
if (!isset($tableposts))
$tableposts = $wpdb->posts;
$info = get_bloginfo('url');
$info = apply_filters('bloginfo', $info);
$homeurl = convert_chars($info);
$today = getdate();
$this_month = $today['mon'];
$this_day = $today['mday'];
$this_year = $today['year'];
if ($this_day < 10) {
$this_day = "0".$this_day;
}
$getyear = $this_year;
for ($i=1; $i <=$showmonths; $i++) {
$getmonth = $this_month - $i;
if ($getmonth <= 0) {
$getmonth = 12 + $getmonth;
$getyear = $getyear - 1;
}
if ($getmonth < 10) {
$getmonth = "0".$getmonth;
}
$getdate = $getyear."-".$getmonth."-".$this_day;
$forurl = $getyear.$getmonth.$this_day;
$forDisplay =
$getmonth.$dateSeparator.$this_day.$dateSeparator.$getyear;
if ($i > 1) {
$isPlural = 's';
} else {
$isPlural = '';
}
$past = $wpdb->get_results("SELECT * FROM $tableposts WHERE post_date LIKE '".$getdate." %'");
if ($past) {
echo $before."This day ".$i." month".$isPlural." ago";
if ($showDate) {
echo ": ".$forDisplay;
}
echo "";
if ($showTitle) {
echo ":".$beforeTitleGroup;
foreach ($past as $post) {
$post_title = stripslashes ($post->post_title);
echo
$beforeTitle.$post_title.$afterTitle;
}
echo $afterTitleGroup;
}
echo $after;
}
}
}
?>