As you may know, older versions of Wordpress do not support the use of widgets. So if you needed to design a theme for someone with an older version of Wordpress this method would be perfect. For me, I needed to place the recent posts in a place where it just wouldn’t make sense to use widgets because the only widget I would need was the recent post widget. It would also take a lot of extra effort.
I figured there had to be an easier way to display the recent posts. I looked through Wordpress’ website and searched Google, but I came up empty handed. So I took it upon myself to write the code for this apparently easy task.
<?php
global $post;
$posts = get_posts(’numberposts=5&offset=0′);
foreach($posts as $post) :
setup_postdata($post);
?>
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
<?php endforeach; ?></ul>
Feel free to use this if you want.
-Greg
EDIT: I have been alerted that there is a VERY similar code. I’m sorry if you have something similar, but this is 100% original.