How to Display Recent Posts with Thumbnails in WordPress

Okay, lets get started. Open functions.php (or create it in case you dont have one but I doubt it). To make use of the thumbnails, firstly we need to activate them using the next piece of code:

let`s write the function, inside the same functions.php file.

?>
<ul>
<?php
function delicious_recent_posts() {
    $del_recent_posts = new WP_Query();
    $del_recent_posts->query('showposts=3');
        while ($del_recent_posts->have_posts()) : $del_recent_posts->the_post(); ?>
            <li>
                <a href="<?php esc_url(the_permalink()); ?>">
                    <?php the_post_thumbnail('delicious-recent-thumbnails'); ?>
                </a>
                <h4>
                    <a href="<?php esc_url(the_permalink()); ?>">
                        <?php esc_html(the_title()); ?>
                   </a>
                </h4>
            </li>
        <?php endwhile;
    wp_reset_postdata();
}
?>
</ul>
<?php

The code is easy to understand. We assigned a new wp query to the $del_recent_posts variable which acts exactly like a WordPress loop, but for the things we asked it to use (showposts=3). So, as long as the query finds posts, generates a list of items which displays the latest 3 posts with thumbnail() and title().

The piece of code is written in a minimal manner, but you can add HTML markup like divs with classes to style the widget in your own way.

In order to make it work, you have to call the function anywhere in your WordPress theme (single.phpfooter.phpsidebar.php, etc), with the next line of code. Most people are using it inside the sidebar.

<?php echo delicious_recent_posts(); ?>
<?php echo delicious_recent_posts('showposts=3'); ?>

That should be all. This is how you could showcase your recent posts with thumbnails, without using a plugin.

niteshbhardwaj.com in Delhi NCR, niteshbhardwaj.com in Laxmi nagar, niteshbhardwaj.com in Ganesh nagar, niteshbhardwaj.com in shakarpur, niteshbhardwaj.com in Ramesh park, niteshbhardwaj.com in Nirman Vihar, niteshbhardwaj.com in Geeta colony, niteshbhardwaj.com in Mandawali, niteshbhardwaj.com in west vinod nagar, niteshbhardwaj.com in karkardooma, niteshbhardwaj.com in Preet vihar, niteshhardwaj.com in Shadipur, niteshbhardwaj.com in Rajouri garden, niteshbhardwaj.com in Bara khamba, niteshbhardwaj.com in yamuna bank, niteshbhardwaj.com in joshi colony, niteshbhardwaj.com in Chandar vihar, niteshbhardwaj.com in Manglam School, niteshbhardwaj.com in Madhu vihar, niteshbhardwaj.com in Mayur vihar, niteshbhardwaj.com in Alla colony, niteshbhardwaj.com in Dwarka, niteshbhardwaj.com in Noida, niteshbhardwaj.com in Greater Noida