Agile Tortoise

Greg Pierce’s blog

« The wayback machine, sort of      Drupal crash course »

Wordpress “last year” listing

Something I had setup in Conversant and missed in Wordpress is the “Last year” listing, which has now been added to the sidebar on this site. Briefly shows 5 topics on the blog from one year ago at this time. This is actually my first WordPress coding, so I don’t know if it’s a bit sloppy, but here’s how I got it to work…

<h3>Last year</h3>
  <ul>
  <?php
    $year = date('Y');
    $month = date('m');
    $lastyear = $year - 1;
    $posts = get_posts('numberposts=5&year=$lastyear');
    global $wpdb;
      $posts = $wpdb->get_results ("SELECT " .
        "* " .
        "FROM $wpdb->posts " .
        "WHERE ( TO_DAYS( NOW() ) - TO_DAYS( post_date ) ) > 364 " .
        "ORDER BY post_date DESC " .
        "LIMIT 5" );
    ?>
  <?php
    foreach($posts as $post):
      setup_postdata($post);
      ?>
      <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach
  ?>
  </ul>
  

Share/Save/Bookmark

Wednesday, August 16th, 2006 at 8:47 am and is filed under WordPress. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply