A dash of PHP

It turns out that it takes longer to write this post, than it does to add the PHP to list the recent WordPress posts, thanks to a few simple function calls wrapped in a loop to fetch the posts:

<div>
  <h3>Latest News</h3>
  <ul>
    <?php require('./blog/wp-blog-header.php'); ?>
    <?php query_posts('showposts=8'); ?>
    <?php while (have_posts()): the_post(); ?>
      <li>
        <span><?php the_date('j/n'); ?></span>
        <a href="<?php the_permalink(); ?>">
          <?php the_title();?>
        </a>
      </li>
    <?php endwhile; ?>
  </ul>
</div>

This is a vanilla WordPress loop construct with a few tweaks to suit my use here. The ‘showposts=8’ parameter limits the number of posts to be listed to 8 and the more cryptic ‘j/n’ parameter for query_posts, formats the date as day/month without leading zeros.

Leave a Reply