As a WordPress site owner, one of your main goals is to provide as much valuable content to your visitors as possible.

One way to do that is by displaying a list of your latest posts within a Wordpress post or page. That way, if a visitor enjoys what they read, they can easily find and click on additional content. This not only improves your chances of getting more page views — it also enhances the visitor experience on your site.

To reap these benefits on your site, we’ll cover the different ways you can create and add a display of recent posts to your WordPress posts and pages. Let’s get started.

Use HubSpot tools on your WordPress website and connect the two platforms  without dealing with code. Click here to learn more.

We’ll walk through each of these methods below so you can choose the one that best aligns with your technical experience. Let’s begin with the easiest method: using the recent posts widget in WordPress.

Display Recent Posts with WordPress’s Built-in Widget

WordPress’s built-in recent posts widget is easy to use for site owners at all skill levels. In exchange for this simplicity, however, you’ll be limited in functionality.

To start, simply log in to your WordPress dashboard and click Appearance > Widgets. Drag and drop the widget labeled “Recent Posts” into your sidebar.

In your sidebar, click on the widget to expand its settings. Here, you can provide an alternate title to the widget, display the publish dates of each post, and choose the number of posts you want to display. Once you’ve made these changes, click the Save button to store the widget’s settings.

The settings of WordPress's built-in recent posts widget

Source

Below is an example of what a Recent Posts Widget looks like in the sidebar of a live site.

Example of what the WordPress Recent Posts Widget looks like in the sidebar of a live site

Source

While this widget is limited in functionality, it may meet the needs of your site. If you need more customization options, however, or would like to display this list anywhere other than in your site’s sidebar, then you can use a plugin. Let’s look at the recent posts plugins below.

Plugins to Display Recent Posts in WordPress

The built-in widget may be too basic for your site. You may want to display thumbnails and excerpts with your recent posts, for example, or limit the posts displayed to specific categories or tags. In that case, you can use one of the plugins below.

WordPress Recent Posts Widget Extended Plugin

The Recent Posts Extended widget provides more customization options than the built-in widget, which gives you more control over the display of recent posts on your WordPress site. You can include custom-sized image thumbnails and excerpts for each post in the display. You can select the order in which posts are displayed, limit which categories and tags these posts can be pulled from, and much more.

Take a look at all of the plugin’s settings below. (Note that the posts are set to display in descending order and by date, which means the latest posts will appear first.)

Settings of the WordPress Recent Posts Widget Extended Plugin

Source

If you’d like to display a list of recent posts anywhere else on your site — say, at the end of a post — you can use the shortcode that comes with the plugin: [rpwe].

You simply need to copy and paste this shortcode into any post or page to display a list of your five latest posts. Below are just two options for configuring the shortcode to customize the list of posts.

Options for configuring the shortcode that comes with the WordPress Recent Posts Widget Extended Plugin

Source

Smart Recent Posts Widget

The Smart Recent Posts Widget is similar to the Recent Posts Extended widget. It allows you to display a list of your latest posts with thumbnails, excerpts, and publish dates included. You can also decide what order the posts are displayed in and limit the display to posts from particular categories and tags.

What sets the Smart Recent Posts Widget apart is how well-organized its settings are. With this plugin, you can fill in the information for one tab and then click on the next, saving changes as you go.

Settings of the Smart Recent Posts Widget

Source

It also offers a few additional settings than the Recent Posts Extended widget, including options to display the posts’ author and comment count as well as three style options.

Below is how a modern-style widget might appear on the front-end of your site.

A Smart Recent Posts Widget in the modern style might look like this on front-end of your site

Source

The disadvantage of using the Smart Recent Posts Widget plugin is that it does not come with a shortcode. That means you can only use this widget to display a list of recent posts in the sidebar of your site.

If you’re looking for the customizability of the Smart Recent Posts Widget combined with the flexibility of the WordPress Recent Posts Widget Extended plugin to display recent posts anywhere on your site, you can add code to your WordPress theme. Let’s walk through the steps below.

Display Recent Posts with Code

If you’re a more advanced user, you can manually display recent posts on your site by adding code to the functions.php file of your theme.

To access this file, log in to your cPanel account with your web host and click on the File Manager. Open your wp-content folder and find your themes folder. Right-click to edit it.

Right-click to edit the functions.php file in a control panel

Source

You can add the code below to your theme’s functions.php file between the PHP tags. The PHP tags look like this: <?php.....?>

 

 

function wpcat_postsbycategory() {

// the query

$the_query = new WP_Query( array( 'category_name' => 'yourcategoryslug', 'posts_per_page' => 10 ) ); 

 

// The Loop

if ( $the_query->have_posts() ) {

    $string .= '<ul class="postsbycategory widget_recent_entries">';

    while ( $the_query->have_posts() ) {

        $the_query->the_post();

            if ( has_post_thumbnail() ) {

            $string .= '<li>';

            $string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 50, 50) ) . get_the_title() .'</a></li>';

            } else { 

            // if no featured image is found

            $string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';

            }

            }

    } else {

    // no posts found

}

$string .= '</ul>';

 

return $string;

 

/* Restore original Post Data */

wp_reset_postdata();

}

// Add a shortcode

add_shortcode('categoryposts', 'wpcat_postsbycategory');

 

// Enable shortcodes in text widgets

add_filter('widget_text', 'do_shortcode');

 

Make sure to replace 'yourcategoryslug' in the third line with the category you’d like the posts to display from. And, if you’d like to display a certain number of posts, just change the “10” in ‘posts_per_page’ => 10 to the number you want.

Adding this code snippet to your functions.php file will enable the shortcode [categoryposts]. You can copy and paste this shortcode into any WordPress post or page to display a customizable set of posts from your WordPress database.

Creating Your Display of Recent Posts

Using any of the methods above, you can display a list of recent posts within your WordPress posts and pages. Choose the method that best meets your site’s needs and aligns with your technical experience.

Because making a mistake in the functions.php file can break your site, adding code is only recommended for users with some coding knowledge. If you’re a WordPress beginner, then we recommend the built-in widget or a plugin.

Wordpress Plugin HubSpot

 Use HubSpot tools on your WordPress website and connect the two platforms  without dealing with code. Click here to learn more.

Originally published Jan 10, 2020 2:52:31 PM, updated January 10 2020

Topics:

WordPress Website