Howto: Generating a list of earlier posts in Wordpress
Saturday, July 30th, 2005I had this feature in my earlier weblog. I had ten posts on the home page and I wanted to show in the sidebar a list of the ten posts that pre-dated the ones on the homepage. You can see the unstyled list on the sidebar right now. I used the get_posts function that comes in Wordpress. Although the_date function is supposed to work only within The Loop, somehow it works here. Here’s the code I used.
<ul id=\"earlierposts\"> <?php $posts = get_posts('numberposts=10&offset=10&order=ASC'); foreach ($posts as $post) : start_wp(); ?> <?php echo \"<li><a href=\"\"; the_permalink(); echo \"\">\"; the_title('', '', true); the_date('j M','</a> <em>','</em></li>'); ?> <?php endforeach; ?> </ul>