"Sidebar Widgets" and drag and drop the widget wherever you want to show it. 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. */ /* Define and activate widgets and dashboard */ global $wp_version; function widget_atd_init(){ if (!function_exists('register_sidebar_widget') || !function_exists('register_widget_control')) return; register_sidebar_widget( 'Around this date', 'widget_atd_display' ); register_widget_control( 'Around this date', 'widget_atd_control', 475, 570 ); } function atd_dashboard_widget(){ widget_atd_display(); } function atd_dashboard_edit(){ echo 'Soon...'; } function dashboard_atd_init(){ wp_add_dashboard_widget('In the past...', 'Around these days in the past...', 'atd_dashboard_widget', 'atd_dashboard_edit'); } if (version_compare($wp_version, '2.7', '>=')) add_action('wp_dashboard_setup', 'dashboard_atd_init'); add_action( 'plugins_loaded', 'widget_atd_init' ); /* Plugin function */ function around_this_date( $daysbefore, $daysafter, $mode, $yearsago, $lastxyears, $sinceyear, $limit, $none, $showyear, $showdate, $dateformat, $showexcerpt) { echo ''; wp_reset_query(); remove_filter('posts_where', 'atd_filter_where'); } break; case 3: // since year x mode for($year = 1; $year <= (date("Y")-$sinceyear); $year++) { $liststart = '
  • '; echo $liststart; get_old_posts( $daysbefore, $daysafter, $year, $limit); atd_loop($atd_the_query, $showdate, $showexcerpt, $dateformat, $none); echo $listend; echo ''; wp_reset_query(); remove_filter('posts_where', 'atd_filter_where'); } break; } } function get_old_posts($daysbefore, $daysafter, $year, $limit) { // global $wpdb; // global $wp_version; global $query_string; $years_ago = date("Y")-$year; $start_ago = date("d-m-Y",strtotime("- ".$years_ago." ".$days_before." days")); $end_ago = date("d-m-Y",strtotime("- ".$years_ago." ".$days_after." days")); add_filter('posts_where', 'atd_filter_where',10,2); $atd_the_query = new WP_Query(array( 'post_status' => 'publish', 'post_type' => 'post', 'showposts' => $limit, 'order' => 'ASC' )); remove_filter('posts_where', 'atd_filter_where'); return $atd_the_query; } function atd_filter_where($start_ago, $end_ago){ $where .= " AND post_date >= ". $start_ago ." AND post_date <= ". $end_ago . ""; return $where; } function atd_loop($atd_the_query, $showdate, $showexcerpt, $dateformat, $none) { if (!empty($atd_the_query)) { while ($atd_the_query->have_posts()) : $atd_the_query->the_post(); echo '
  • '; echo '' . get_the_title() . ''; if($showdate) { echo ' - ' . get_the_date($dateformat) . '
    '; } if($showexcerpt) { echo '' . get_the_excerpt() . ''; } echo '
  • '; endwhile; } else { echo '
  • ' . $none . '
  • '; } echo ''; } /* Widget options */ function widget_atd_options() { $defaults = array( 'title' => 'This week last year...', 'daysbefore' => 3, 'daysafter' => 3, 'mode' => 1, 'yearsago' => 1, 'lastxyears' => 1, 'sinceyear' => 2006, 'limit' => 4, 'none' => 'none', 'showyear' => true, 'showdate' => false, 'dateformat' => 'F j', 'showexcerpt' => false ); $options = (array) get_option('widget_atd'); foreach ( $defaults as $key => $value ) if ( !isset($options[$key]) ) $options[$key] = $defaults[$key]; return $options; } function widget_atd_display() { $options = widget_atd_options(); echo $before_widget . $before_title . $options['title'] . $after_title; around_this_date( $options['daysbefore'], $options['daysafter'], $options['mode'], $options['yearsago'], $options['lastxyears'], $options['sinceyear'], $options['limit'], $options['none'], $options['showyear'], $options['showdate'], $options['dateformat'], $options['showexcerpt'] ); echo $after_widget; } function widget_atd_control() { $options = $newoptions = widget_atd_options(); if ($_POST['atd-submit']) { $newoptions['title'] = strip_tags(stripslashes($_POST['atd-title'])); $newoptions['daysbefore'] = strip_tags(stripslashes($_POST['atd-daysbefore'])); $newoptions['daysafter'] = strip_tags(stripslashes($_POST['atd-daysafter'])); $newoptions['mode'] = strip_tags(stripslashes($_POST['atd-mode'])); $newoptions['yearsago'] = strip_tags(stripslashes($_POST['atd-yearsago'])); $newoptions['sinceyear'] = strip_tags(stripslashes($_POST['atd-sinceyear'])); $newoptions['lastxyears'] = strip_tags(stripslashes($_POST['atd-lastxyears'])); $newoptions['limit'] = strip_tags(stripslashes($_POST['atd-limit'])); $newoptions['none'] = strip_tags(stripslashes($_POST['atd-none'])); $newoptions['showyear'] = isset($_POST['atd-showyear']); $newoptions['showdate'] = isset($_POST['atd-showdate']); $newoptions['dateformat'] = strip_tags(stripslashes($_POST['atd-dateformat'])); $newoptions['showexcerpt'] = isset($_POST['atd-showexcerpt']); } if ( $options != $newoptions ) { $options = $newoptions; update_option('widget_atd', $options); } $title = attribute_escape($options['title']); $daysbefore = (int) $options['daysbefore']; $daysafter = (int) $options['daysafter']; $mode = (int) $options['mode']; $yearsago = (int) $options['yearsago']; $sinceyear = (int) $options['sinceyear']; $lastxyears = (int) $options['lastxyears']; $limit = (int) $options['limit']; $none = attribute_escape($options['none']); $showyear = ($options['showyear'] ? 'checked="checked"' : ''); $showdate = ($options['showdate'] ? 'checked="checked"' : ''); $dateformat = attribute_escape($options['dateformat']); $showexcerpt = ($options['showexcerpt'] ? 'checked="checked"' : ''); ?>
    :






    :
    :




    See PHP Date manual