How to display recent posts on WordPress pages

There are many ways to display recent posts on WordPress pages without using bulky plugins and default features that cause headaches and slow down your website. There are also different options you can use to embed certain WordPress posts. For example, you can display recent posts in a list, display recent posts in a drop-down menu, and you can even display all WordPress posts if you wish to.

The PHP codes below can be added into your WordPress template pages and files in order to display recent WordPress posts on certain pages.

Display recent posts in a list

<?php get_archives('postbypost', '30', 'custom', '', '<br />'); ?>

The above PHP snippet will allow you to display 30 recent posts. To change the amount of recent posts to display, simply change the 30 to any number.

Display recent posts per day(s)

<?php wp_get_archives('type=daily&limit=15'); ?>

The above PHP snippet can be used to display the most recent WordPress posts from the last 15 days. To change the amount of days pulled, switch the 15 above with any numeric.

Display recent posts per month(s)

<?php wp_get_archives('type=monthly&limit=12'); ?>

The above PHP snippet can be used to display the most recent WordPress posts from the last 12 months (1 year). To change the amount of  months, switch the 12 above with any numeric.

Display recent syndication feeds

if ( isset ( $query->query_vars['feed'] ) and ( $query->query_vars['feed'] == 'ics' ) )
	add_filter( 'post_limits', '__return_empty' );

The “Syndication feeds show the most recent” or ‘posts_per_rss‘ parameters in Settings > Reading will overwrite any ‘posts_per_page‘ parameter in a query used in a feed. Read More.

Display recent posts in a drop-down list

<form id="archiveform" action="">
<select name="archive_chrono" onchange="window.location =
<option value=''>Select Month</option>
<?php get_archives('monthly','','option'); ?>

Use this to display a drop-box menu of your monthly archives with post counts displayed.

You also can use the piece of code below instead to show month lists, including the number of posts/month.

 <select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
 <option value="">Select month</option>
 <?php get_archives('monthly',,'option',,,'TRUE'); ?>

Display all WordPress posts alphabetically

<?php wp_get_archives('type=alpha'); ?>

Display all your WordPress posts alphabetically. Sure it’s not essentially display “recent” posts but is an alternative.

Sean Doyle

Sean Doyle is a tech author and engineer with over 20 years of experience in cybersecurity, privacy, malware, Google Analytics, online marketing, and other topics. Sean's content has been featured in numerous publications.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.