How to Display Your Recommended Posts in WordPress

The enumerated steps below will display a list of your Recommended Posts with thumbnail images in the sidebar of your WordPress-powered website. The list will be consist of five titles right next to their corresponding images. This tutorial uses a WordPress category to display the list.

If after reading this article you want a different method of doing the same thing, you may read the article How to Display Your Featured Posts in WordPress.

1. Add the following lines of code to the functions.php file:

// Set image sizes
add_theme_support('post-thumbnails');
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 50, 50, array( 'center', 'center') );
add_image_size( 'excerpt-image', 60, 40 ); // 60px is the width, 40px is the height
}

2. Add the following bits of code to the sidebar.php file:

<div class="posts-recommended widget">
<h4 class="widget-title">Recommended Posts</h4>
<ul>
	<?php 
	$theme_featured_posts = new WP_Query('posts_per_page=5&category_name=Recommended');
	if ( $theme_featured_posts->have_posts() ) : while ($theme_featured_posts->have_posts()) : $theme_featured_posts->the_post(); 
	?>
		<li>
			<div class="image-widget"><a href="<?php esc_url(the_permalink()); ?>"><?php the_post_thumbnail(''); ?></a></div>
			<div class="title-widget"><a href="<?php esc_url(the_permalink()); ?>"><?php esc_html(the_title()); ?></a></div>
		</li>
	<?php endwhile; ?>
	<?php endif; ?>
	<?php wp_reset_postdata(); ?>
</ul>
</div>

3. Add the following lines to the style.css file:

.widget-title {
font-size: 30px;
font-weight: bold;
padding-bottom: 5px;
}

.widget ul {
list-style-type: none;
text-align: left;
padding-left: 0;
margin-left: 0;
display: block;
}

.widget li {
margin-bottom: 40px;
height: 10px;
display: inline-block;
}

.widget li img {
display: inline-block;
margin-left: 0;
margin-right: 10px;
width: 60px;
height: 40px;
float: left;
}

.widget li a {
vertical-align: top;
}

4. Go to Posts > Categories in the WordPress dashboard and create a new category.

Write Recommended as the name, recommended as the slug, choose none for the Category Parent, and then click Add New Category.

5. Go to Posts > Add New in the WordPress dashboard and create a new post.

Tick the checkbox next to the category Recommended in the Categories box on the right. Click Publish.

6. Repeat Step 5 as many times as you want.

If you want a different method of doing the things taught in this tutorial, you may read the article How to Display Your Featured Posts in WordPress.