Tim Yang’s Weblog

30/7/2023

Howto: Generating a list of earlier posts in Wordpress

Filed under: Howto, Wordpress — Tim Yang @ 4:41 pm

I 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>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress