Top 3 Ways of Showing Recent Posts in WordPress Code Theme or Sidebar
Displaying recent posts in your WordPress is a norm nowadays on every other WordPress or Blogger blog, Now you can use any of these codes / methods to get yourself a nice recent posts list for last 10 “X number of posts “ .
1. Recent Posts Using the wp_get_archives function
<?php wp_get_archives(‘title_li=&type=postbypost&limit=10’); ?>
This would list recent 10 posts , in their own <li> tags , you can use this after post-meta or the_content () in single.php to list recent posts after every Post , or use it in any of your Sidebars.
2. Recent Posts Using the WordPress query function to query the Posts database
<?php query_posts(‘showposts=5’); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
This piece of code can be used anywhere in your theme , as it is self sufficient and it will display recent 5 posts, change the value of “showposts=5” variable to whatever no. of posts you want
3. Recent Posts widget / Plugins for the novice and beginners
If you are a noob at wordpress and still want to get the recent posts functionality , then try the various plugins available to do the work for you. You can use any of these ..
OR Use the Add plugin option in your WordPress Dashboard, and search for recent posts and you can install the plugin from their directly and easily .
Out of the 3 mentioned above I would recommend using first 2 , as they give you more control but only if you know some PHP and programming , otherwise go for the plugins ( it’s the easy way out ! ).