Here's a nice idea to give a second life to your old posts—automatically displaying the posts you published exactly one year ago. In this recipe, you'll learn how to do just that by using some simple PHP, the WordPress loop, and the super-useful query_posts()
function.
In the previous recipe, I showed you how to get posts for the day. Now, let's use the same code and modify it a bit to get all posts published exactly one year ago.
This code can be used anywhere in your theme files. However, I recommend using it in single.php
, between display of the post and the comments template.
<?php $current_day = date('j'); $current_month = date('m'); $last_year = date('Y') -1; query_posts('day='.$current_day.'&month='.$current_month. '&year='.$last_year); if (have_posts()) : while (have_posts()) : the_post(); ?> // WordPress loop endwhile; endif; ?>