We had earlier taught how to display random posts in WordPress without using any plugins. Now this short tutorial will teach you how to display recent/latest posts on your WordPress blog without using any plugin. Though there is a widget that display recent posts in your sidebar, it doesn’t let you display anywhere else you like to. Say for instance, if you want to display the recent posts in footer like the one below in this blog, you will have to use few lines of code along with few template tags. So let’s get started!
How to display recent posts in WordPress without using any plugins:
- Login to your WordPress Dashboard and navigate to Appearance > Editor
- Now decide where to display the recent posts. For instance if you want to display after single post, then open “single.php”
- Paste this code where you want the recent posts to appear. (Don’t put it in any of the PHP loops).
<ul>
<?php
global $post;
$myposts = get_posts('numberposts=6&offset=1');
foreach($myposts as $post) :
setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
Just in case if you want to customize the list, a small explanation might help:
In line 4, you can see numberposts=6. This will display 6 recent posts. You may increase or decrease the number as your wish. Then, offset=1 will exclude one latest post since we are displaying recent posts and not the latest posts. You can set it to zero to display as latest posts.
Update the file and you are done. Now it will display a list of recent posts in your single posts or wherever you place it.


