How to feature your recent WordPress posts on home page

Posted on:

With content marketing being all the rage, you are writing blog posts consistently. It’s a great user experience to display your most recent posts, right on the homepage.

Your audience will find your latest posts easily. Your home page will have a refreshed look every time new posts are put out.

Here are two examples of websites that have taken this approach.

So by now, you are convinced about this tactic to get your audience to your latest posts. But what if your theme doesn’t support this feature? What if you don’t want to clog your WordPress admin with yet another plugin.

Well, fret no more. I’m going to show you an easy way to get two of the recent blog posts with a featured image, to show up on the home page. With a little bit of code and a cup of hot masala chai, let’s get your latest posts on the home page. No plugins will be harmed:-)

Here is what the end result will look like.

Steps To Feature Your Recent WordPress Posts On Home Page

  1. Open the front-page.php file from your WordPress theme directory.
  2. Go to the location where you want the recent posts to be displayed in the .php file.
  3. Copy and Paste the code snippet and make the necessary changes to suit your needs and theme structure.
/* Code snippet to feature two recent posts on home page */

//2 is the number of posts to display on the home page
$args = array( 'numberposts' => 2 );
$lastposts = get_posts( $args );

//change the div class based on your theme structure
echo '<div class="article-container">';
foreach($lastposts as $post) : setup_postdata($post);
echo '<article>';
if (has_post_thumbnail()){ ?>;

//getting the featured image of the post
<figure class="featured-image">
<a href="<?php echo esc_url(get_permalink());?>" rel="bookmark">
<?php the_post_thumbnail(); ?>
<?php } ?>

//getting the post title
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php echo '</article>';
echo '</div>';?>;

That’s it. Your most recent posts with the featured image will be displayed on the home page.

I hope this article helped you to understand how to feature the recent posts on the home page with no plugins. I used this quick and easy method to get my recent posts on my home page and on several client projects.