How To Add Related Posts Widget To Blogger with Thumbnails

Now here is a wonderful hack for displaying related posts beneath each of your blog posts, along with thumbnails. The related articles are chosen from other posts in that same category/label/tag. With this hack many of your readers will remain on your site for longer periods of time when they see related posts of interest.

Related: Related posts widget with thumbnails and summaries.

related post, related posts blogger, blogger widgets

Adding the Related Posts Widget to Blogger/Blogspot

Step 1. Log in to your Blogger account and go to Template > Edit HTML

blogger template, edit html

Step 2. Click anywhere inside the code area and press the CTRL + F keys:

blogger search box, CTRL + F

Step 3. Search for this piece of code adding it inside the search box (hit Enter to find it):
</head>
Step 4. Copy and paste the below code just before/above the </head> tag:
<!--Related Posts with thumbnails Scripts and Styles Start-->
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<style type='text/css'>
#related-posts{float:left;width:auto;}
#related-posts a{border-right: 1px dotted #eaeaea;}
#related-posts h4{margin-top: 10px;background:none;font:18px Oswald;padding:3px;color:#999999; text-transform:uppercase;}
#related-posts .related_img {margin:5px;border:2px solid #f2f2f2;object-fit: cover;width:110px;height:100px;-webkit-border-radius: 5px;-moz-border-radius: 5px; border-radius: 5px; }
#related-title {color:#333;text-align:center;text-transform:capitalize;padding: 0px 5px 10px;font-size:12px;width:110px; height: 40px;}
</style>
<script type='text/javascript'>
//<![CDATA[
var relatedTitles=new Array();var relatedTitlesNum=0;var relatedUrls=new Array();var thumburl=new Array();function related_results_labels_thumbs(json){for(var i=0;i<json.feed.entry.length;i++){var entry=json.feed.entry[i];relatedTitles[relatedTitlesNum]=entry.title.$t;try{thumburl[relatedTitlesNum]=entry.gform_foot.url}catch(error){s=entry.content.$t;a=s.indexOf("<img");b=s.indexOf("src=\"",a);c=s.indexOf("\"",b+5);d=s.substr(b+5,c-b-5);if((a!=-1)&&(b!=-1)&&(c!=-1)&&(d!="")){thumburl[relatedTitlesNum]=d}else thumburl[relatedTitlesNum]='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2JUNyQOEclTr808bDlZKRBHftyWOFyKt_tm0S53j8NaAgkePxN8X6853967-t3316e6Sg6cMOfhCaMKnuHL-IprhgIyn5ro33fQ1c08dj3WKaOTMKwX0cKnEFuG2CU3K_Ac-ejUQQQl1v/s1600/no-thumbnail.png'}if(relatedTitles[relatedTitlesNum].length>35)relatedTitles[relatedTitlesNum]=relatedTitles[relatedTitlesNum].substring(0,35)+"...";for(var k=0;k<entry.link.length;k++){if(entry.link[k].rel=='alternate'){relatedUrls[relatedTitlesNum]=entry.link[k].href;relatedTitlesNum++}}}}function removeRelatedDuplicates_thumbs(){var tmp=new Array(0);var tmp2=new Array(0);var tmp3=new Array(0);for(var i=0;i<relatedUrls.length;i++){if(!contains_thumbs(tmp,relatedUrls[i])){tmp.length+=1;tmp[tmp.length-1]=relatedUrls[i];tmp2.length+=1;tmp3.length+=1;tmp2[tmp2.length-1]=relatedTitles[i];tmp3[tmp3.length-1]=thumburl[i]}}relatedTitles=tmp2;relatedUrls=tmp;thumburl=tmp3}function contains_thumbs(a,e){for(var j=0;j<a.length;j++)if(a[j]==e)return true;return false}function printRelatedLabels_thumbs(){for(var i=0;i<relatedUrls.length;i++){if((relatedUrls[i]==currentposturl)||(!(relatedTitles[i]))){relatedUrls.splice(i,1);relatedTitles.splice(i,1);thumburl.splice(i,1);i--}}var r=Math.floor((relatedTitles.length-1)*Math.random());var i=0;if(relatedTitles.length>0)document.write('<h4>'+relatedpoststitle+'</h4>');document.write('<div style="clear: both;"/>');while(i<relatedTitles.length&&i<20&&i<maxresults){document.write('<a style="text-decoration:none;margin:0 4px 10px 0;float:left;');if(i!=0)document.write('"');else document.write('"');document.write(' href="'+relatedUrls[r]+'"><img class="related_img" src="'+thumburl[r]+'"/><br/><div id="related-title">'+relatedTitles[r]+'</div></a>');if(r<relatedTitles.length-1){r++}else{r=0}i++}document.write('</div>');relatedUrls.splice(0,relatedUrls.length);thumburl.splice(0,thumburl.length);relatedTitles.splice(0,relatedTitles.length)}
//]]>
</script>
</b:if>
<!--Related Posts with thumbnails Scripts and Styles End-->
Note:
- to change the width and height of thumbnails, modify the 110px and 100px values in red
- to change the color and size of related posts titles, change the value in blue
- remove the line in violet if you want the related posts to be displayed both in homepage and post pages.

Step 5. Find the line below (you will find two times, but you need to stop at the second one):
<div class='post-footer'>
Step 6. Just above <div class='post-footer'> paste this code:
<!-- Related Posts with Thumbnails Code Start-->
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<div id='related-posts'>
<b:loop values='data:post.labels' var='label'>
<b:if cond='data:label.isLast != &quot;true&quot;'>
</b:if>
<script expr:src='&quot;/feeds/posts/default/-/&quot; + data:label.name + &quot;?alt=json-in-script&amp;callback=related_results_labels_thumbs&amp;max-results=5&quot;' type='text/javascript'/></b:loop>
<script type='text/javascript'>
var currentposturl=&quot;<data:post.url/>&quot;;
var maxresults=5;
var relatedpoststitle=&quot;<b>Related Posts:</b>&quot;;
removeRelatedDuplicates_thumbs();
printRelatedLabels_thumbs();
</script>
</div><div class='clear'/><div style="font-size: 9px;float: right; margin: 5px;"><a  style="font-size: 9px; text-decoration: none;" href="https://bloggerchive.blogspot.com/2012/03/how-to-add-related-posts-widget-to-blogger.html" rel="nofollow" >Related Posts Widget</a></div>
</b:if>
<!-- Related Posts with Thumbnails Code End-->
Note:
- change the 5 value from max-results=5 with the number of posts you want to be displayed
- if you want the related posts to be displayed on homepage too, then remove the lines in violet

Update! If you are unable to see the related posts widget after saving the template, add the code (step 5) just above the </b:includable> tag which can be found above this line (CTRL + F to find it):
<b:includable id='postQuickEdit' var='post'>
For more info, click on this screenshot below:

Add related post widget to Blogger.

Step 7. Save the Template and that's it. Now the Related Posts widget should appear below each blog post that has labels on it. Enjoy!

Comments/disqusion
302 comments

  1. says:

    Nice.. Tip.. I like the Big thumbnails better..
    Is there any chance i could also increase the amount of Text displayed under the thumbnail?
    http://maghrb.com/
    Some related posts topics makes no sense when its half.

  2. says:

    mine doesn't work.. nothing change..=(

  3. says:

    Hello, thanks for your instructions, I've put your codes on my blog, it works properly, but I would like to change it minimal, could you help me?

    1. I would like to put the widget in the middle after end of posts. After writing commend

    #related-posts{float:center;width:auto;}

    nothing's changing.

    2. I would like to change the adjustment of pictures to the frame - I would like to have cutted photos in squares, now photos are fitted to squares and one of them are stretched which doesn't look pretty.

    3. I would like to have 7 or 8 photos, but the maximum I have is 4. What should I do?

    Thanks for helping, Alice.

    here is my blog http://konturek.blogspot.com/

  4. says:

    thanks!! that's great, i will put it in my blog http://qneblog.blogspot.com

    thanks!!

  5. says:

    Hi Ala,

    1. You need to add the margin-left property instead of float: center (you can't center elements by using float):
    #related-posts{margin-left: 200px;}
    Where 200px is the distance from the left. Change this value to move it more on the left/right.
    2. I'm sorry but I don't know any solution for this using CSS, it would require using jQuery and it's a bit more complicated to explain here. Maybe I'll make a tutorial about it soon.
    3. Have you tried to change the two "5" values from max-results=5 (step 6)?

  6. says:

    Thank you for this post it helped me a lot

    http://softwareofnet.blogspot.com/

  7. says:

    This is great. Thanks a ton! Very well explained. I appreciate you taking the time!

  8. says:

    thanks bro for sharing this useful post. Can you suggest me how to show full post title.

  9. says:

    I did as you instructed but it's not working for me :(

  10. says:

    I did as instructed and it works Thanks a ton !

  11. says:

    Amazing! Thank you so much!!

  12. says:

    THANK YOUUUUUUUUUU!!! it WORKED like magic...
    tried linkwithin and failed, so I turned to your method :)
    thanks.
    http://deetje2.blogspot.com

  13. says:

    Thank you! Finally something that works!

  14. says:

    Urgh it doesn't work for me.. beginning to hate blogger!

  15. says:

    Thanks a lot!! after a long search..this is effective.

  16. says:

    nice post, working good

  17. says:

    Could not get this to work at all. :(

  18. says:

    It really works - thanks a lot :)
    http://napadydoskolky.blogspot.cz/

  19. says:

    Its not working on my blog. Does it depends on Templates also?

  20. says:

    Thank You For The Effective Instructions. It's working but one problem. Since the background colour of my blog is black, the titles of the related posts are blurry and illegible. I want them to be bold red or bold white. Please help.

  21. says:

    Thank you, inspired by you i solved the text problem myself though its still slightly hazy (changed it to white so its looking okay :) ...But some of the pics in thumbnails remain blank, especially for lengthy post pages. Please help. I have great faith in your skills!

  22. says:

    Hello,
    I added this code in my blog and it was working fine but suddenly the widget disappeared and now it is not showing anything.The code is still running in my blog.please help.

  23. says:

    in my blog i got two, i put the code above the second "div class='post-footer'
    div class='post-footer-line post-footer-line-1>"
    thanks it works

  24. says:

    Sadly, didn't seem to work at all. Even had my neighbor who is in school for web design come over~ couldn't seem to get it to work either. I did try and remove the code so it would show on my home page. I'm getting a lot of traffic to my blog right now and could really use this feature. Would love help if you have time :0) www.goldilockskitchen.com

  25. says:

    Hi Emily,

    Add the code from step 6 below the second <data:post.body/> (instead of <div class='post-footer'>) and see if it works. Thanks for visting!

  26. says:

    Works perfectly in my blog (http://diluartempurungku.blogspot.com) :) Thank you soooo much!

  27. says:

    Can you please help?! I have been trying to get this to work for an hour and don't see any thumbnails. I have plenty of labels on my posts and copied and pasted as you instructed. My blog is lifeontheflycounselor.blogspot.com ---not sure if that will help you figure out what I did wrong. Thanks!

  28. says:

    Bro it's not working on my blog i tried all your instruction and read all other comments but no luck still not working in my blog..please help..want this feature so bad...

  29. says:

    I don't understand why it works on some blogs, but not on others. Does it depend on whether you're using the "classic" template or one of the new ones? I'm using "Simple."

  30. says:

    Thank you so much for this! It works perfectly!

  31. says:

    Thanks for sharing! I just added it to my blog: http://vickilesage.blogspot.fr/

  32. says:

    really helpful post for beginner ..thanks.

  33. says:

    Thanks for your widget! but how can i increase the the related post title characters number?

  34. says:

    thanks you for the information , my blog success 100%.

  35. says:

    Best Tutorials gathered in a single place. Really appreciate your work!

  36. says:

    nice gan...visit back!!

  37. says:

    Hello! Thank you very much for sharing this code, but it doesn't work for me (
    When I try to apply it, it says "can't load the template, syntacsis mail: The string "--" is not permitted within comments.

    What am I doing wrong?

  38. says:

    I did everything as you instructed but it doesn't work (I stopped at the second one of step 5) and pasted the code above it . What's the problem? and how to do. Please help, thanks.

    Moondy

  39. says:

    FYI, if you change the width, also change it in the CSS (step 4) on the line that starts #related-title. Otherwise it won't center the text on the image.

  40. says:

    It doesn't work for me for some reason. I believe I followed the instructions well, however, for some reason, it does not appear on my blog. Does it take some time before it appears may be? (I installed it- or rather tried to install it- about 10 minutes ago. Please help! (Thank you)

  41. says:

    its not working on my blog

  42. says:

    thank you :)

  43. says:

    Thanks so much! But how do you change the font type of the 'related posts' text?

  44. says:

    Thanx bro...
    Being still in blogspot like me..

  45. says:

    Hi, I've just added the code exactly how you instruct both in the head and the div class='post-footer immediately after div class='post-footer-line post-footer-line-1' and nothing is showing up on my blog. Any thoughts as to what I'm doing wrong?
    www.interiorfrugalista.com

  46. says:

    I cant find post footer even after using ctrl+f

  47. says:

    I wonder why it did not work for me

  48. says:

    It really worked! Thank you.. I almost back to wordpress before read your tutorial :)

  49. says:

    Hi Marie Blackburn,

    I've updated my post, please add the code from step 5 above the </b:includable> tag which is just above <b:includable id='postQuickEdit' var='post'>. You can see more info in the above screenshot. I hope it will work now...
    Sorry for the late reply!

  50. says:

    Please try to add the code from step 5 above the </b:includable> tag which is just above <b:includable id='postQuickEdit' var='post'>. You can see a screenshot above. I hope it will work now...

  51. says:

    Hey Miss_Mapple,

    I'm glad that it worked :) Thanks for stopping by!

  52. says:

    Try to add the code from step 5 just above the </b:includable> tag which is above this line:
    <b:includable id='postQuickEdit' var='post'>
    Please take a look at the screenshot above for more help. Thanks for visiting!

  53. says:

    can't save template after paste

  54. says:

    hi ... it worked well ... but after few days , the thumbnails are not displaying :( . What should i do now ?

  55. says:

    i've done two steps but can't find step three on my blog. Coil you help me pls? My blog www.rudymspojrzeniemnaswiat.blogspot.com i will appreciate

  56. says:

    Hi Elaine,

    Please make sure that the </head> tag has no blank spaces before/after it.

  57. says:

    My mistake, i was thinking about step 5. I can't find div class='post-footer' :(

  58. says:

    what code you means in last paragraph, if unable see related post,copy code in step 5..

    please help me.

  59. says:

    after few days , the thumbnails are not displaying :( . Please help me ... http://remixmama.blogspot.in/

  60. says:

    It is not working & I don't know why?

  61. says:

    It works like a charm into my blog http://www.pinoytechtalk.net

    Thanks!!

  62. says:

    I like the results. Many thanks!

  63. says:

    Hi,
    Thumbnails are not appearing.. any way to fix?

  64. says:

    too complicated and not dry for me , is there any simpler way ? (beside using linkwithin.com which appear to be broken on blogspot..)

  65. says:

    This is great. Thanks! Any idea how to add a horizontal line (or border) under the "Related Posts"? I'd really appreciate the help!

  66. says:

    Hi Kristy,

    Find this line in the html of your template (step 4):
    #related-posts{float:left;width:auto;}

    And replace it with this one:
    #related-posts {border-bottom: 2px solid #000000;float: left;width: 100%;}

    Thanks for visiting!

  67. says:

    You rock man, this widget worked perfectly! Thank you so much.

  68. says:

    Thank you very much, it works. But it is strange, that the current post is also shown in the "related posts". Is der a possibility to avoid this?

  69. says:

    thank you!

  70. says:

    Hi thank you so much for your help. I spend my whole day in finding and fixing the codes but all went in vein. But after reading your this tutorial I made it in 5 mins. My blog looks beautiful....
    http://buyingknivesonline.blogspot.in/

  71. says:

    Thank You. How do I add more spacing between post and "Related Post" text?

  72. says:

    Wow! Thank you! It really worked!

  73. says:

    Hi I used your method for related posts as in this .....

    http://helplogger.blogspot.in/2012/03/how-to-add-related-posts-widget-to.html ....

    It was working fine , but after few days the Thumbnails of the related post disappeared can please help me with it ... thank u

    this is my site pls take a look ...

    http://remixmama.blogspot.in/2014/05/intertellar-trailer-directed-by.html

  74. says:

    You will need to put the pictures first and then the videos, since this script will read the first element which should be an image (it doesn't read video thumbnails). Thanks for visiting!

  75. says:

    Hey bud. Its not workingn on my blog. Tried everything and no luck. Could it be because of my theme? can you pls help me. its mahubya.blogsot.com Thanks!

  76. says:

    thanks very useful, worked for me!

  77. says:

    it's not working for me. tried it exactly the way you explained but it still isn't working

  78. says:

    works perfectly !

  79. says:

    Thank you for this tip! I have featured your post with a link on my blog :)

  80. says:

    hello admin. Thank you so much. After searching for related post, i found this and it worked! thanks again

  81. says:

    This does not work on my nblog. I tried it both ways you said.

  82. says:

    thank you so much!

  83. says:

    this is so useful and i successfully added into my blog, thanks!

  84. says:

    For the first time I feel like leaving a comment. I have searched many blogs and posts on "how to add related articles on blogger" and none of them worked. This is the only one that really worked and it is also written in a very easy and understandable way that any one (even people like myself who doesn't speak english fluently). Whoever wrote this post, I have to say only one word...CONGRATULATIONS!

  85. says:

    Hellou, i'm still have a problem with this. I cant't find div class=post-footer in my html code. I check few times if it's put correct. and it is. pls help!

  86. says:

    Thank you. it works.

  87. says:

    div class='post-footer ' i find it only one time in my blog....

  88. says:

    Thanks Bro it works fine.But i have a little problem. When i increase the max no. of posts to 8 then it shows 4 posts in one line, two posts in next line and remaining two in third line. So there are blank spaces in line 2 and line 3. Please tell me how can i align them to fit in two lines only

  89. says:

    thankz a lot.

  90. says:

    Thx...how posted only related urls, without images?

  91. says:

    What can I do to have related posts on page, below the option Read more? Now I have related posts only when i open the post.

    And thank you for sharing this codes :)

  92. says:

    First of all thanks a lot for this..It works but I face few minor problems..
    1.The title case becomes mixed case eg: "RELeated PoSTs" (so had to remove the title for now).
    2.Some times the order becomes distorted(occasionally) eg: currently i use 8 recommendations so it will show 3 in a row, 4 in a row and 1 in a row.
    If you can fix these i would be very happy,..Thanks Again...

  93. says:

    it doesn't work for me, could you help me please? it doesn't show up :(

  94. says:

    how about on a template that you download with a related post already in it? I can't customize it. :(

  95. says:

    i doesnot work

  96. says:

    hello i have used this code beneath my individual posts but the thumbnails appear after the comments - can you let me know how to make them appear before the comments? thanks in advance

  97. says:

    Is there any way to increase the number of characters?

    http://thefemaleambiguity.blogspot.com/

  98. says:

    Thank, it's worked

  99. says:

    Go to LayOut > Favicon ( on top left),

  100. says:

    I got only text - no thumbnail pics. Any advice?

  101. says:

    Terrific post! Thanks so much for your help!

  102. says:

    I have the same problem >>> Magen @ Crumpled Fantasies4/16/2013
    This code works, but my thumbnails are misshapen. it forces the default photo to be a square thumbnail but the photo is often not square which leaves the the photo looking odd. can i change that?

    How can I fix this? Tnx!