How to Display Recent Posts in WordPress

WordPress

Displaying recent posts in WordPress is a commonly done thing. Visitors like user-friendly websites and if they can find the post they are looking for in the sidebar, it will save them from roaming around the site aimlessly. If you are a regular reader of WordPress blogs, you will notice that many of the leading sites use the recent posts feature and, in fact, many of the modern themes now include the latest post display option as standard. Getting such a theme is obviously an easy way of showing off recently published posts to readers; however, the feature may not necessarily be designed to your liking.

Here is a guide on how to display recent posts in different ways:

Display Posts in List Format

The recent posts list format is arguably one of the most popular methods of displaying content in the side bar.

To do this, locate the sidebar.php template file and copy and paste the following code:

<?php get_archives('postbypost', '5', 'custom', '<li>', '</li>'); ?>

You can see from this that I have used the number 5; this refers to the number of posts that you wish to display. You can change this number according to your preferences; however, five is a good amount.

If you don’t like editing codes, an easier option is to head over to Appearance > Widgets, locate the Recent Posts widget, drag it over to the sidebar menu and select the number of posts you wish to display.

Display Posts with Summary

A small summary of what the post is about will help readers greatly in finding deciding whether to commit to reading. Using code, simply copy and paste the following in the necessary template file:

<ul>

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

</ul>

Summaries have word limits, so you will need to write a short description of the blog post to suit. To customize word limit, you can go to Plugins > Add New and search for Limit Post Add On. This plugin will let you decide the word limit of your posts and even add a “Read More” option.

Display Posts with Full Content

The full content option is one that is rarely used, but is useful for those running the WordPress content management system for a business website. Displaying full content makes your page look like a blog page, so if you are running WordPress.com, the feature will not be necessary.

To display full content, select the template file where you wish the recent posts to be displayed, and copy and paste the following code:

<ul>

<?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_content(__('(more…)')); ?></li>

<?php endwhile;?>

</ul>

Once again, the number 5 is used here (‘showposts=5’ ) which can be changed accordingly; however, with full content, it’s best not to overdo it otherwise you risk recent posts overshadowing other content.

All successful WordPress sites are big on usability; following this guide to display recent posts will help make your site more appealing to visitors, benefitting your reader-base as a result.

Share it!Share on FacebookTweet about this on TwitterShare on Google+Email this to someone

Our Recommended Wordpress Web Hosting Provider

WordPress

WHC.CA
Get a 50% Discount by using our link.

WHC.ca

Reliable host, with excellent customer service and an easy one-click Wordpress installation. Our recommendation to host a Wordpress blog.

Leave a Reply

Your email address will not be published. Required fields are marked *