Display Recent Posts in WordPress


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

Add recent posts in WordPress with PHP

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>
<?php endwhile;?>

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.

Tags: |
Nord VPN Sale

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Similar Articles


Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2020 UseThisTip Developed By Deepanker