WordPress: More customizable ways of displaying recent posts

When using the WordPress widgets to display the most recent posts, the level of customization is somewhat reduced, provided the user does not want to alter the way WordPress displays the resulting lists.

The following code snippets show how to display the most recent posts in WordPress, to be used on either the sidebar or footer sections of a theme, in the case you do not use the WordPress widgets. These allow customization in a somewhat easy way.

This code will display the 10 most recent posts, from newest to oldest, in a vertical list format.

$args = array( 'numberposts' => '10' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ) {
	echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' . $recent["post_title"].'</a></li>';

The next code snippet displays the 10 most recent posts with the date before the entry title, from newest to oldest, in a list format:

<?php $postslist = get_posts('numberposts=10&offset=1&order=DESC&orderby=post_date');
foreach ($postslist as $post) :
setup_postdata($post); ?>

<li><?php the_time('d.m.y') ?>  <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php endforeach; ?>

And here you go, two examples of displaying recent posts in another way.