Many times we need to display recent posts on side bar or content page of WordPress blogs. If it is for side bar, we can use existing widget to display recent posts. But for content we need do some PHP code modification. You can use this code on any play where you want to display recent posts
So Here I am adding some ways to display recent posts on WordPress
Display Only Title of Recent Posts
If you want to display only titles of recent posts, you can use following code where you want to display the posts.
<?php get_archives('postbypost', '10', 'custom', '<li>', '</li>'); ?>
Here number 10 represents the number of post which you want to display.
Displaying Recent Posts with Summary
Sometimes, we are interested in showing post summery along with the titles of recent posts. For this, we can use following code.
<?php $the_query = new WP_Query( 'showposts=5' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php the_excerpt(__('(more…)')); ?></li>
Here you can change the number 250 to any number. It represents the number fo characters of summery that will be displayed along with the title of recent posts.
If you think there are more easy ways to show recent posts on the page, you can share with us.
If you like this post, share it with your friends on various social media websites.