Categories

How to create recent posts page

Rating: 5.0/5. From 1 vote.
Please wait...

This tutorial will show you how to create a recent posts list page in WordPress. In other words you’ll learn how to create a page that will display recent posts title in a list format.

Before you start this tutorial please make sure you learned how to add pages and create page templates in WordPress.

1. Access your theme directory (wp-content/themes/theme###)

2. Create new page, create new page template and assign it to the page.

3. Open the created page template file

4. To display a posts list we’ll use the WordPress core tag wp_get_archives.

This tag has several arguments:

 <?php $args = array(
    'type'            => 'monthly',
    'limit'           => ,
    'format'          => 'html', 
    'before'          => ,
    'after'           => ,
    'show_post_count' => false,
    'echo'            => 1 );
 ?>

You should insert the tag into your page template file and assign necessary arguments.

The following code will make your page display 20 recent posts:


<?php
/*
Template Name: Recent Posts
*/
?>
<?php get_header(); ?>
		<div class="container">
			<div class="indent">
				
				<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

					<?php wp_get_archives('type=postbypost&limit=20&format=custom'); ?>

				<?php endwhile; ?>
					
			</div>
		</div>
<?php get_footer(); ?>

 

Let’s see some other usage examples:

Display posts for the last 12 months

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

Display posts for the last 15 days

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

Display 20 last posts

<?php wp_get_archives('type=postbypost&limit=20&format=custom'); ?>

 

Best Templates Wordpress
This entry was posted in WordPress, WordPress Tutorials and tagged archived_tutorial, core, limit, post, recent, tags, WordPress. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket