February 7, 2014 / IST / Tips & Tricks, Web Development.

Displaying Category posts often helps your users to visit them easily specially on the sidebar of a single post page. But in some designing processes people want to display recent posts in many different ways. In this post, we will show you various different ways you can display the recent posts in WordPress.

Displaying Recent Posts in a List Format

<ul id="recent_post">
<?php
    $recent = new WP_Query('cat=1&showposts=5');
    while($recent->have_posts()): $recent->the_post();
?>
    <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__ ('Permanent Link to %s', 'Pointer Brain'),get_the_title())?>">
        <?php the_title(); ?></a>
    </li>
<?php
    endwhile;
    wp_reset_postdata();
?>
</ul>

 Displaying Recent Posts with Summary

<ul id="recent_post">
<?php
	$recent = new WP_Query('cat=1&showposts=5');
	while($recent->have_posts()): $recent->the_post();
?>
	<li>
		<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__ ('Permanent Link to %s', 'Pointer Brain'),get_the_title())?>">
		<?php the_title(); ?></a>
		<p><?php the_excerpt(__('(more…)')); ?></p>
	</li>
<?php
	endwhile;
	wp_reset_postdata();
?>
</ul>

 Displaying Recent Posts with Limit Content

<ul id="recent_post">
<?php
    $recent = new WP_Query('cat=1&showposts=5');
    while($recent->have_posts()): $recent->the_post();
?>
    <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__ ('Permanent Link to %s', 'Pointer Brain'),get_the_title())?>">
        <?php the_title(); ?></a>
        <p><?php the_content_limit(250); ?></p>
    </li>
<?php
    endwhile;
    wp_reset_postdata();
?>
</ul>

  Displaying Recent Posts with Full Content

<ul id="recent_post">
<?php
    $recent = new WP_Query('cat=1&showposts=5');
    while($recent->have_posts()): $recent->the_post();
?>
    <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__ ('Permanent Link to %s', 'Pointer Brain'),get_the_title())?>">
        <?php the_title(); ?></a>
        <p><?php the_content(__('(more…)')); ?></p>
    </li>
<?php
    endwhile;
    wp_reset_postdata();
?>
</ul>

 Displaying Recent Posts with Thumbnail

<ul id="recent_post">
<?php
    $recent = new WP_Query('cat=1&showposts=5');
    while($recent->have_posts()): $recent->the_post();
?>
    <li>
        <?php
            if ( has_post_thumbnail() ) {
                the_post_thumbnail();
            }
            else {
                echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/no-images.jpg" />';
            }
        ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__ ('Permanent Link to %s', 'Pointer Brain'),get_the_title())?>">
        <?php the_title(); ?></a>
    </li>
<?php
    endwhile;
    wp_reset_postdata();
?>
</ul>

 

You may change the ahowposts number 5 and cat numberto whatever you like. 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.

Now you should be able to display Recent Posts in your WordPress blog or a CMS.