How to Display Recent Posts in WordPress

It’s always good to serve your website visitors with recent posts on the home page in the sidebar. In fact, displaying latest post on sidebar is one of the most user-friendly ways of navigation through which one can easily land to specific blog post without roaming around unnecessary.  However, most of the WordPress themes/ templates used to come with automatic latest post display option by default. But, what if one want to display recent posts from specific category only.

In today’s post of CSSChopper, we would like to discuss how you can show Recent Posts in the sidebar from a specific category without a Plug-in in WordPress CMS. By using WordPress hack, you can easily display your latest posts from a specific (single) category. Before that, we will tell you different ways to display the recent posts in WordPress.

How to Display Recent Posts in WordPress

Displaying Recent posts on the sidebar of a single post page allow targeted set of visitors to visit the latest posts easily. Show date-based archives list of recent posts in the page by simply pasting the following code:

<h2>Recent Posts</h2>
<ul>
<?php get_archives('postbypost', 6); ?>
</ul>

However, there are many other ways through which you can display your recent posts with great ease in WordPress. Let’s take a look:

1. Displaying Recent Posts in a List Format

Simply paste the following codes to show recent post in the list format in the sidebars of website:

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

2. Displaying Recent Posts with Summary

Simply paste the following codes to display latest posts with summary including title and a short description.

<ul>
<?php query_posts(‘showposts=5’); ?>

<?php while (have_posts()) : the_post(); ?>

<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li><li><?php the_excerpt(__(‘(more…)’)); ?></li>
<?php endwhile;?>
</ul>

3. Displaying Recent Posts with Full Content

By copying and pasting following codes you can display recent posts with full content (in WordPress only).

<ul>
<?php query_posts(‘showposts=5’); ?>

<?php while (have_posts()) : the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>

<li><?php the_content(__(‘(more…)’)); ?></li>
<?php endwhile;?>

</ul>

How to Display Recent Post from a specific category

To show recent post from a specific category simply copy and paste the following codes. By this, you can easily recent posts in the sidebar from a specific category without a Plug-in in WordPress.

<?php
query_posts(’showposts=5&orderby=date&cat=3?);
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h3>
<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>

In the above mentioned code, cat=26 symbolizes category ID number and showposts=10 stands for recent posts from specific category count. Don’t forget to check specific category ID from admin panel, manage, categories while adding the above codes to sidebar.php file.

Posted By: CSSChopper Team

Ready to get started? Fill the form now!

Related Posts

z
 

Looking for a Web Development Services?

Request a FREE Quote.