Easy Way To Display Recent Posts in WordPress

By

September 6, 2012Wordpress5 Comments

With WordPress is becoming one of the largest self-hosted blogging tool across the globe, its benefits are being exploited by millions of site owners and is being explored by tens of millions of people each day. Everything that has been created on WordPress has been crafted by and for the community. Since it is an open source it gives you an opportunity to modify it to the suit your needs. One of them is displaying your recent posts to generate traffic and benefits beyond discussion in this article. Here are some ways for you to display recent posts and keep your readers informed on all your recent updates.

wordpress_logo1

(Image Source: WordPress.org)

1. It’s easier than you might think

 

Of course you don’t require any training or custom queries for this one. All you need to know is the inbuilt function in WordPress to get the recent posts on your static web page. And that’s not all – you can create your own widget with no plugin. Being more than a blogging system, you can try the below mentioned coding and go miles amongst your readers.

 

This could be a great start for you as a beginner and later also try giving links to your recent posts. You can also use the function wp_get_archives() with which some parameters can help you publish recent WordPress posts.

 

2. Some technical friendly idea

 

To give this idea a try, you should have the WordPress installed on a PHP Web Server else you should use a web hosting. To get started you would need a code editor along with FTP support. You should also be familiar with XHTML and a little CSS and PHP. Open your code editor and the file where you would want to add this snippet. Try for top of the page and at the area where you would like your recent posts to appear type the following:

 

$args = array( ‘numberposts’ => 6,
‘post_status’=>”publish”, ‘post_type’=>”post”,’orderby’=>”post_date”);
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>

 

Opting to explore this idea can help you experience the world of WordPress. Infact you can use some tricks even to hide or mask posts as per your convenience and choice. You can even customize your default Recent Posts widget to show or hide your posts by categories.

 

Displaying Recent Posts in a List Format

The list format is mostly used in sidebars of WordPress pages. You can display the recent posts by simply pasting the following code in a template file of your choosing for example sidebar.php:

 

<?php get_archives(‘postbypost’, ’10′, ‘custom’, ‘<li>’, ‘</li>’); ?>


You can change the number 10 to the number of posts you like to display.If your theme support Widgets, then there is an easier option for you. You can simply head over to the widgets page and add Recent Posts widget to your sidebar. That will save you from editing the codes.

 

Displaying Recent Posts with Full Content

Some people like to display recent posts with full content if WordPress is being used as a Content Management System (CMS).

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


This is mostly used to make a page look like your blog page.So you should not need this if you are not running a CMS.

 

Conclusion

All you need is a little time and you can easily display your recent posts as a WordPress user. Since this tool has a wonderful CMS capability you can actually design your page and site as per your style and mind. It can get really easy to add this option to your sidebar and get famous amongst your target audience. Always remember the code editor may highlight some errors but the PHP code will take care of all your worries in this case. It will execute the code with the help of .htaccess snippet. Try to create a fresh page to test this functionality before you try this on your live page.

Written by Alyssa. Edited by Aritra Roy.

 

Alyssa has been doing internet marketing, SEO Services for last 5 years. She loves travelling, meeting new people and works at SEO Morpheus.

5 Responses to “Easy Way To Display Recent Posts in WordPress”
  1. Excellent tips for a savvy web developer who is getting familiar with wordpress! I like the idea of having a widget like you guys do on the side where you can quickly switch between popular and latest post sort options. Nice!
    Brandon Johnson recently posted..Amazing Website Designs Leveraging Impress.js and Great Web Design ConceptsMy Profile

  2. Ashley says:

    Hi Aritra,
    I learned a lot from reading your blog. But for displaying the recent posts, isn’t it the default sitebar widget for most of the themes? You just need to drag the “recent posts” widget to the sitebar, it’ll be fine.

    • Aritra Roy says:

      You are definitely correct. This is so far one of the most easiest way to display recent comments in your blog. But in this post you will learn ways to customize your recent posts widget the way you want it to be. :-)

  3. Nizam Khan says:

    Well, wordpress is really great for customizations with great features. Thanks Alyssa for sharing these snippets for displaying recent posts :)

Leave a Reply

CommentLuv badge
This blog uses premium CommentLuv which allows you to put your keywords with your name if you have had 5 approved comments. Use your real name and then @ your keywords (maximum of 1)