How to: Show Recent Articles in WordPress (without plugin / widget)

Similarly with the post to display the recent comments of your WordPress blog, you can even tell your visitors about your last written or latest articles of your blogs.

For this purpose, there are already plenty of plugins and widgets that provide this functionality, but it's just without the use of additional plugins. A code snippet that shows the last article of your blog, you will find in this article.

The code to determine the last item

The following code can be used in the functions.php file to be copied:

function get_latest_posts($limit = 3)
$latest_posts = get_posts('numberposts=' . $limit);

$output = '<ul>';
foreach($latest_posts as $post)
$post_title = $post->post_title;
$post_permalink = get_permalink($post->ID);

$thumbnail = get_the_post_thumbnail(
'class' => '',
'alt' => $post_title,
'title' => $post_title

$output .= '<li><a href="' . $post_permalink . '" title="Artikel: ' . $post_title . '">';
$output .= $thumbnail . '<span>' . $post_title . '</span></a></li>';

$output .= '</ul>';

return $output;

To determine the last item we need, as you can see, a single line of SQL, but only the function get_posts () (line 3) with the parameter number posts. Default if when calling get_latest_posts () not otherwise specified, the last written 3 articles are fetched from the database.

The second portion (lines 5-23) the composition is the output. In this example we simply create a list item for each <li> </ li>, which in turn contains a link, the link to the relevant article. The link text consists of our article thumbnail and the title of the article.

The code to display the last items

The following code can be placed anywhere in your WordPress theme. Would you like eg the list of the last 7 articles in the sidebar, you can add the following code example in the sidebar.php to insert.

1.echo  get_latest_posts (7);


The edition you can customize and make your wishes by using CSS.

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.