"Sidebar Widgets" and drag and drop the widget wherever you want to show it.
Changelog
v.0.6.2 = Fixed a bug when having & in post's title. Isolated repetitive code in its own function. Changes contributed by Mike Koepke.
v.0.6.1 = Fixed bug when having quotes in post's title. Thanks to Mike Koepke for bug repporting and helping with fixing.
v0.6 = Added 2 new modes, last X years and since year X.
Corrected bug in $start_ago and $end_ago.
v0.5.2 = XHTML valid. Lu�s P�rez (aka Cin�filo)
v0.5.1 = Now the $yearsago parameter works.
v0.5.01 = Now the limit option works, for real ;)
v0.5 = First release. I decided to start on version 0.5 because of preserving version relation with �One year ago� plugin.
Thanks
Thanks to Borja Fernandez, Chris Goringe and Sven Weidauer for writing their plugins and to Luis P�rez and Mike Koepke for their contributions.
*/
function around_this_date ( $daysbefore = '3', $daysafter = '3', $mode = '1', $yearsago = '1', $lastxyears= '1', $sinceyear='2006', $limit = '4', $none = 'none')
{
if ($mode == '1') { // "classic" mode
$start_ago = (365*$yearsago)+$daysbefore;
$end_ago = (365*$yearsago)-$daysafter;
get_old_posts( $start_ago, $end_ago, $limit);
}
elseif ($mode == '2') { // last x years mode
for($year = 1; $year <= $lastxyears; $year++) {
$start_ago = (365*$year)+$daysbefore;
$end_ago = (365*$year)-$daysafter;
get_old_posts( $start_ago, $end_ago, $limit);
}
}
elseif ($mode == '3') { // since year x mode
for($year = 1; $year <= (date("Y")-$sinceyear); $year++) {
$start_ago = (365*$year)+$daysbefore;
$end_ago = (365*$year)-$daysafter;
get_old_posts( $start_ago, $end_ago, $limit);
}
}
}
function get_old_posts( $start_ago, $end_ago, $limit, $none)
{
global $wpdb;
$entries = $wpdb->get_results ("SELECT " .
"ID, post_title " .
"FROM $wpdb->posts " .
" WHERE post_status = 'publish' AND (( TO_DAYS( NOW() ) - TO_DAYS( post_date ) ) BETWEEN " . $end_ago . " AND " . $start_ago . ")".
" ORDER by 'asc'" .
" LIMIT $limit"
);
print "
";
if ($entries) {
$output = ''; // empty the 'output' string
foreach ($entries as $entry) {
$title = str_replace('"', '',$entry->post_title);
$title = htmlspecialchars($title);
$output .= '