Tim Yang’s Weblog

Jump to content

About Tim Yang’s Weblog

Nothing to see here.

Categories

Archives

Tags


-->

Howto: Generating a list of earlier posts in Wordpress

Jul 2005
30

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>

Your Comment

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>




Credits

Copywriter Malaysia