Your WordPress site is already online and visitors are pouring in, that’s already a good thing.

Unfortunately, your visitors will not always be aware of the latest articles published on your site, unless they are subscribed to your newsletter or mailing list.

To inform your visitors of the latest articles published on your site, you must display the list of recent articles.

Show recent posts on WordPress

It’s a relatively simple process. To achieve this result, you have the choice between the 3 methods below.

Utiliser la fonction WP_QUERY

The following lines of code will allow you to display recent articles published on your site. You can just set the number of articles to display.

<h3>Derniers articles</h3> <ul> <?php $recentPosts = new WP_Query(); $recentPosts->query('showposts=5'); ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>

Show recent posts with the QUERY POSTS feature

The query posts function does not have a good reputation in terms of performance. However, these lines of code will be very appreciated by novices.

$args = array( ‘numberposts’ => 5, ‘order’=> ‘ASC’, ‘orderby’ => ‘title’ );
$postslist = get_posts( $args );
foreach ($postslist as $post): setup_postdata($post); ?>

<li><?php the_title(); ?></li>
<?php endforeach; ?>
You can add additional information to these lines of code:
<?php the_excerpt(); ?>: an extract from your article;
<?php the_date(); ?>: the publication date of the article;
<?php the_category(); ?>: the category in which the post appeared;

These 3 methods will allow you to create custom loops to display your latest posts anywhere on your WordPress blog.

Use a widget to display recent posts

This method remains the simplest, especially if you don’t want to delve into lines of code. You can use the official WordPress Widget.

Here’s how to do it.

Go to the Appearance menu of your WordPress site administration interface, then click on Widgets.

Click/drop the Recent Posts widget to the location of your choice. You just need to reassure yourself that your theme has the locations for this purpose.

Scroll to Top