Related Posts with Thumbnail for Blogger / Blogspot

Related Posts Widget is a utility that is quite important. By helping visitors see the related article, they will stay on our site longer. This Widget will search for and print out a random articles have the same label.

Related Posts with Thumbnail for Blogger / Blogspot

Adding related posts widget to Blogger / Blogspot

To make it easy to edit, replace or delete if you do not want to use it. I will create it in the b:includable tag. Now find
<b:includable id='post' var='post'>
above it paste the following code.
<b:includable id='related-posts'>
<style type='text/css'>
#related-posts {float:left}
#related-posts ul{margin:0;padding:0;list-style-type:none}
#related-posts ul li{padding:8px 0}
#related-posts img{float:left;border:1px solid #BBB;margin-right:10px;width:72px;height:72px;background:#FFF;padding:3px}
#related-posts h3{margin:0;font-size:16px}
</style>
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<div style='clear:both'/>
<div class='col-sm-6' id='related-posts'>
<script type='text/javascript'>
var ry='<h2>RELATED POSTS</h2>';
rn='<h2>No related post</h2>';
rcomment='Comments';
rdisable='Comments Disabled';
commentYN='yes';
</script>
<script type='text/javascript'>
//<![CDATA[
var dw='';titles=new Array();titlesNum=0;urls=new Array();timeR=new Array();thumb=new Array();commentsNum=new Array();comments=new Array();function related_results_labels(c){for(var b=0;b<c.feed.entry.length;b++){var d=c.feed.entry[b];titles[titlesNum]=d.title.$t;for(var a=0;a<d.link.length;a++){if('thr$total'in d){commentsNum[titlesNum]=d.thr$total.$t+' '+rcomment}else{commentsNum[titlesNum]=rdisable};if(d.link[a].rel=="alternate"){urls[titlesNum]=d.link[a].href;timeR[titlesNum]=d.published.$t;if('media$thumbnail'in d){thumb[titlesNum]=d.media$thumbnail.url}else{thumb[titlesNum]='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtARBGHl-4orQ4vfU5jPcGitN72J1ZgTjiOAUja3MWDHnRiUCt9rxYlr1Pspu0m6L01o58q13ve_SE9fiIqJvIRiwcr5VKDAxaa_WYqrXiQYMzbARylH5Kj8i8NWVpLkx86LTZD1IbukO/'};titlesNum++;break}}}}function removeRelatedDuplicates(){var b=new Array(0);c=new Array(0);e=new Array(0);f=new Array(0);g=new Array(0);for(var a=0;a<urls.length;a++){if(!contains(b,urls[a])){b.length+=1;b[b.length-1]=urls[a];c.length+=1;c[c.length-1]=titles[a];e.length+=1;e[e.length-1]=timeR[a];f.length+=1;f[f.length-1]=thumb[a];g.length+=1;g[g.length-1]=commentsNum[a]}}urls=b;titles=c;timeR=e;thumb=f;commentsNum=g}function contains(b,d){for(var c=0;c<b.length;c++){if(b[c]==d){return true}}return false}function printRelatedLabels(a){var y=a.indexOf('?m=0');if(y!=-1){a=a.replace(/\?m=0/g,'')}for(var b=0;b<urls.length;b++){if(urls[b]==a){urls.splice(b,1);titles.splice(b,1);timeR.splice(b,1);thumb.splice(b,1);commentsNum.splice(b,1)}}var c=Math.floor((titles.length-1)*Math.random());var b=0;if(titles.length==0){dw+=rn}else{dw+=ry;dw+='<ul>';while(b<titles.length&&b<20&&b<maxresults){if(y!=-1){urls[c]=urls[c]+'?m=0'}if(commentYN=='yes'){comments[c]=' - '+commentsNum[c]}else{comments[c]=''};dw+='<li><img alt="'+titles[c]+'" src="'+thumb[c]+'"/><div><h3><b><a href="'+urls[c]+'" rel="nofollow">'+titles[c]+'</a></b></h3><span>'+timeR[c].substring(5,7)+'/'+timeR[c].substring(8,10)+'/'+timeR[c].substring(0,4)+comments[c]+'</span></div></li><div style="clear:both"></div>';if(c<titles.length-1){c++}else{c=0}b++}dw+='</ul>'};urls.splice(0,urls.length);titles.splice(0,titles.length);document.getElementById('related-posts').innerHTML=dw};
//]]>
</script>
<b:loop values='data:post.labels' var='label'>
<script expr:src='&quot;/feeds/posts/default/-/&quot; + data:label.name + &quot;?alt=json-in-script&amp;callback=related_results_labels&quot;' type='text/javascript'/>
</b:loop>
<script type='text/javascript'>var maxresults=3;removeRelatedDuplicates();printRelatedLabels(&#39;<data:post.url/>&#39;);</script>
</div>
</b:if>
</b:includable>
You can change
  • ry: Title of related posts
  • rn: Title if there are no related posts
  • rcomment: Comments phrase
  • rdisable: Comments Disabled Phrase
  • commentYN: Show comments Yes or No
  •  maxresults: Number of comments
Now put this code to anywhere you want to show related posts
<b:include name='related-posts'/>
If you want to show it at the end of post find
<div class='post-footer'>
and paste that code below it.

Save your template and you are done.

Recent Posts Widget for Blogger / Blogspot

Typically, these new articles often contain more information than the previous article. But as we all know most visitors come to our website through Google, and they do not know what they are missing in the new post. Therefore adding this widget to helps visitors can see many more useful information.

Recent Post Widget for Blogger / Blogspot

CSS

In the template coding, search for ]]></b:skin> and just above it paste the following code.
img.recent_thumb {padding-right:0.4em;width:72px;height:72px;border:0;
float:left;margin: 0 5px 5px 0;}
.recent_posts_with_thumbs {float: left;width: 100%;min-height: 70px;margin: 5px 0px 5px 0px;padding: 0;}
ul.recent_posts_with_thumbs li {padding-bottom:5px;padding-top:5px;min-height:65px;}
.recent_posts_with_thumbs a {text-decoration:none;}

Javascript

Search for </head> and just above it paste the following code.
<script style='text/javascript'>//<![CDATA[
function showrecentpostswiththumbs(json){document.write('<ul class="recent_posts_with_thumbs">');for(var i=0;i<numposts;i++){var entry=json.feed.entry[i];var posttitle=entry.title.$t;var posturl;if(i==json.feed.entry.length)break;for(var k=0;k<entry.link.length;k++){if(entry.link[k].rel=='replies'&&entry.link[k].type=='text/html'){var commenttext=entry.link[k].title;var commenturl=entry.link[k].href}if(entry.link[k].rel=='alternate'){posturl=entry.link[k].href;break}}var thumburl;try{thumburl=entry.media$thumbnail.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=d}else thumburl='http://www.webaholic.co.in/other/no-image.jpg'}var postdate=entry.published.$t;var cdyear=postdate.substring(0,4);var cdmonth=postdate.substring(5,7);var cdday=postdate.substring(8,10);document.write('<li class="clearfix">');if(showpostthumbnails==true)document.write('<img class="recent_thumb" src="'+thumburl+'"/>');document.write('<b><a href="'+posturl+'" target ="_top">'+posttitle+'</a></b><br>');if("content"in entry){var postcontent=entry.content.$t}else if("summary"in entry){var postcontent=entry.summary.$t}else var postcontent="";var re=/<\S[^>]*>/g;postcontent=postcontent.replace(re,"");if(showpostsummary==true){if(postcontent.length<numchars){document.write('<div>');document.write(postcontent);document.write('</div>')}else{document.write('<div>');postcontent=postcontent.substring(0,numchars);var quoteEnd=postcontent.lastIndexOf(" ");postcontent=postcontent.substring(0,quoteEnd);document.write(postcontent+'...');document.write('</div>')}}var towrite='';var flag=0;document.write('<br><span>');if(showpostdate==true){towrite=towrite+cdmonth+'/'+cdday+'/'+cdyear;flag=1}if(showcommentnum==true){if(flag==1){towrite=towrite+' - '}if(commenttext=='1 '+rcp_comment)commenttext='1 Comment';if(commenttext=='0 '+rcp_comment)commenttext='No Comments';commenttext='<a href="'+commenturl+'" target ="_top">'+commenttext+'</a>';towrite=towrite+commenttext;flag=1}if(displaymore==true){if(flag==1)towrite=towrite+' | ';towrite=towrite+'<a href="'+posturl+'" class="url" target ="_top">'+rcp_readmore+'</a>';flag=1}document.write(towrite);document.write('</span></li>');if(displayseparator==true)if(i!=(numposts-1))document.write('<hr size=0.5>')}document.write('</ul>')}
//]]></script>

Use in Blogger

Now go to Layout at your blog dashboard and  add new HTML/Javscript Gadget, paste the following code inside the empty box.
<script style='text/javascript'>
var rcp_readmore = 'Read more';
var numposts = 5;
var showpostthumbnails = true;
var displaymore = false;
var displayseparator = true;
var showcommentnum = true;
var showpostdate = true;
var showpostsummary = true;
var numchars = 150;
</script>
<script src='/feeds/posts/default?orderby=published&alt=json-in-script&callback=showrecentpostswiththumbs'></script>
In this code you can customize a few things
  • var rcp_readmore  Readmore phrase
  • var numposts  Number of posts to display
  • var showpostthumbnails  Show/hide post thumbnails
  • var displaymore  Show/hide the read more link
  • var displayseparator  Show/hide separator
  • var showcommentnum  Show/hide the number of comments
  • var showpostdate  Show/hide the posts dates
  • var showpostsummary Show or not the posts summaries
  • var numchars Number of posts characters
After everything is done, click on save gadget and your website did have a recent post.

Resize and Crop Thumbnail Image

We all know one of the most annoying things in most of the Blogger Template is the thumbnail image distortion due to the adjustment in css. After a period of time to find out I discovered a trick to help resize and crop the image the correct size by tweaking the url. From there I make this jQuery code that automatically adjust thumbnail for any Blogger Template.

Features

  • Resize images without blurring.
  • Crop the image to the correct size.
  • Only works with image uploading in Blogger and Picassa.
  • Works with many elements of the blog.

How to use in Blogger

Login into Blogger choose your blog and go to Template >> Edit HTML. Now in the template coding, search for </head> and just above it paste the following code.
<script type='text/javascript'>//<![CDATA[
$(document).ready(function() {
  var w = 200;
  var h = 150;
  $('#PopularPosts1, #Related-Posts, .Something-Else').find('img').each(function(n, image){
    var image = $(image);
    image.attr({src : image.attr('src').replace(/s\B\d{2,4}/,'s' + w + '-h' + h +'-c')});
    image.attr('width',w);
    image.attr('height',h);
  });
});
//]]></script>
Now to resize and crop images you just have to add the ID or CLASS of the tag so that it could fetch all the images in it and do job. You can add many common IDs and Classes as you like.

If you want to do this for auto readmore with thumbnail, then you should use this ID "#Blog1" and put the above code in this code.
<b:if cond='data:blog.pageType != &quot;item&quot;'>
  <b:if cond='data:blog.pageType != &quot;static_page&quot;'>
    PUT CODE HERE.
  </b:if>
</b:if>
So ít wont resize and crop at post page.

Once everything is done, save the template by pressing that orange “Save” button located at the top of the screen and now the quality of your images won’t let you down.