How to Add Image Thumbnails to Related Posts in WordPress

Q: Your site is very helpful to me. Could you please tell me how to embed that related posts like in your site in mine? I have tried a lot of alternatives, can you please tell me how you add that related posts with thumbnails?

If you are frequently browsing the Web, you will notice that many blogs are showing image thumbnails for the Related Posts section, just like what we did in Make Tech Easier. In WordPress, there are several ways that this can be done. Let’s check it out.

Using a plugin

The easiest way to implement the image thumbnail (without any coding) is via a plugin. LinkWithin is one such tool that you can use. Advantage of LinkWithin is that it doesn’t take up any of your server space and bandwidth (to store the thumbnails) and there are little (or zero) configurations need to be done.

Go to LinkWithin. Fill in the detail on the front page.

wpthumb-linkwithin

Click Get Widget. You will then be directed to a page where you can download the plugin.

Install and activate the plugin. Your thumbnail related post will immediately appear in your blog.

wpthumb-linkwithin-on-post

As good as it can get, there are some disadvantages and limitation of using LinkWithin.

  1. there is limited control for the end-user: you are not able to configure which image thumbnail to show for each post.
  2. you cannot adjust the size and styling of the widget.
  3. you cannot set the position for the widget to appear. The default is for it to appear immediately after the post content ends, but there are times where you want to insert author information or advertisements first before the related post. in this case, this doesn’t come handy.

Hacking the WP theme file

The best way to fully customize the user experience is to go into the theme file and do some hacking. This will require some coding experience.

First, using the instruction here, activate the post thumbnail feature (only applicable in WP 2.9 and above).

Next, install and activate the Yet Another Related Posts plugin. What I love about this is the ability to use a template system to style up the related post content.

In the YARPP plugin folder, go to the yarpp-templates folder and copy the file “yarpp-template-thumbnail.php” to your theme folder.

Next in the WordPress YARPP options page:

  • uncheck the “Automatically displayed related posts?
  • select the number of related posts that you want to display
  • choose the yarpp-template-thumbnail.php from the template file dropdown list.

wpthumb-yarpp-options

Open the “yarpp-template-thumbnail.php” in a text editor. Replace the code with the following.

What this code does is to check if there is a thumbnail set for each related post. If yes, it will display the thumbnail and the permalink.

Next, in your theme folder, open your “single.php” file and add the following line to the part where you want to display the related post:

Lastly, we need to do some styling. Copy and paste the following styling code to your style.css file.

.related_posts ul{ width:100%; list-style:none; margin:0; padding:0; } .related_posts li { display:inline; float:left; margin:0; padding-left:0; padding-right:10px; width:140px; /* change this value accordingly to your template */ } .related_permalink{ width:140px;/*change this value accordingly to your template */ text-align:left; font-size:0.85em; padding-top:5px; } .related_thumbnail{ width:140px; /*change this value accordingly to your thumbnail size */ height:80px; overflow:hidden; text-align:center; }

That’s it.

Image credit: wuzhao.album

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Damien Oh Avatar

Read next

Suzanne Simard sealed paper birch and Douglas fir seedlings inside plastic bags, fed them carbon-14 and carbon-13 dioxide, and nine days later found carbon had crossed between species through fungal threads in the British Columbia soil beneath her boots
A species of jellyfish called Turritopsis dohrnii can revert its adult cells back to a juvenile polyp stage when injured or starving, effectively restarting its life cycle, and biologists have so far failed to identify any natural limit to how many times it can do this.
A Japanese man named Jiroemon Kimura, who lived to 116, was born in 1897 when Queen Victoria still ruled and died in 2013, meaning a single human life personally overlapped with the invention of the airplane, the atomic bomb, the internet, and Instagram
The Hollywood sign originally read HOLLYWOODLAND when it was built in 1923 as a real estate advertisement for a housing development, and it was only meant to stand for 18 months, but nobody ever got around to taking it down and the city eventually adopted it as a landmark
Almost all of the world’s internet traffic does not travel by satellite but through fibre-optic cables lying on the ocean floor, a hidden web of wires crossing the deepest parts of the sea to connect the continents.
People who flip their phone face down on every table aren’t being secretive. They figured out that staying interruptible meant handing their time to whoever rang first
Twitch vs. Facebook Gaming vs. YouTube Gaming: What’s the Best Live Game Streaming Platform?
Chrome Extensions Ownership Transfer is a Direct Threat to You: How to Stay Safe