How to Show Latest Posts List in Your WordPress Theme

WordPress Image
In this WordPress tutorial I will show how to display list of latest / recent posts in your WordPress theme. We will use WordPress function Recent Posts widget to display list of latest posts.

Syntax

<?php the_widget( 'WP_Widget_Recent_Posts', $instance, $args ); ?> 

Display Recent 5 Posts

<?php the_widget('WP_Widget_Recent_Posts'); ?>

Display Recent 10 Posts

Below code will display list of recent 10 posts and show default title.

<?php the_widget('WP_Widget_Recent_Posts', 'number=10'); ?>

Display Recent 10 Posts and Hide Title

<?php the_widget('WP_Widget_Recent_Posts', array('number' => 10, 'title' => ' '), $args); ?>

Display Recent 10 Posts and Change Default Title

<?php the_widget('WP_Widget_Recent_Posts', array('number' => 10, 'title' => 'My New Title'), $args); ?>

Display Recent 10 Posts and Hide Default Title Tags

<?php the_widget('WP_Widget_Recent_Posts', array('number' => 10, 'title' => ' '), array('before_title' => ' ', 'after_title' => ' ')); ?>