Display Recent posts on the homepage of WordPress

Displaying recent posts on the homepage of your WordPress website can help your visitors easily find new content and keep them engaged with your site. In this guide, we’ll show you how to display recent posts on your homepage using two methods: a plugin and manual code.

Method 1: Use a Plugin

Step 1: Install and activate the plugin The first step is to install and activate a plugin that allows you to display recent posts on your homepage. Some popular options include:

  • Jetpack: A powerful plugin that includes a widget for displaying recent posts.
  • Recent Posts Widget Extended: A lightweight plugin that adds a customizable recent posts widget to your site.
  • WP Recent Posts: Another lightweight plugin that adds a recent posts widget with several customization options.

Once you have chosen a plugin, go to the WordPress dashboard, navigate to “Plugins” > “Add New” and search for your chosen plugin. Install and activate it.

Step 2: Add the widget to your homepage Once the plugin is activated, go to “Appearance” > “Widgets” and find the “Recent Posts” widget. Drag and drop it to your homepage’s widget area.

You can customize the widget’s settings, such as the number of posts to display, the post order, and post date format. Once you’re happy with the settings, save them.

Method 2: Manually Code the Recent Posts

If you prefer to code the recent posts display manually, follow these steps:

Step 1: Create a new file Navigate to your WordPress theme directory (typically found in /wp-content/themes/your-theme-name) and create a new file named “recent-posts.php”.

Step 2: Add the code Copy and paste the following code into the file:

phpCopy code<?php
$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 5, // Change this number to display a different number of posts

$recent_posts = new WP_Query( $args );

if ( $recent_posts->have_posts() ) :
        <?php while ( $recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>
<?php endif; ?>
Step 3: Save the file Save the file and upload it to your theme directory.

Step 4: Add the code to your homepage In your homepage template file (usually called “index.php”), add the following code where you want to display recent posts:

phpCopy code<?php include 'recent-posts.php'; ?>

That’s it! Now your recent posts should be displayed on your homepage.

Note: If you’re not comfortable with coding, it’s best to stick with the plugin method. Modifying code can be risky and cause issues if you don’t know what you’re doing.

Leave a Comment