How to Related Post for Blogspot ?

The following article will guide how to add related posts in Blogger. Add the related posts on every article is a good method to increase the weekly view for your blog.






Step 1: go to > Edit HTML Template and select Expand Widget Templates

Step 2: press Ctrl + F and search to keywords ]] >. Add the code below before the keyword search are
#related-posts{ margin: 15px 0; }
#related-posts ul{ margin: 10px 0 0; padding:0; list-style-type:none; }
#related-posts ul li{ border-top: none !important; border-left: 2px solid #1399CF; border-bottom: 1px dotted #1399CF; margin-bottom: 3px; padding: 3px 0 3px 30px; }
#related-posts ul li:hover { background-color: #1399CF; border-top: none !important; border-left: 2px solid #B3CA3D; border-bottom: 1px dotted #B3CA3D; }
#related-posts h2{ margin:0; font-size:20px; }
#related-posts a{ color: #555; font-size: 16px; }
#related-posts a{ text-decoration: none; }
#related-posts li:hover a,#related-posts li:hover span{ color: #fff; }
#related-posts span{ color: #555; margin-left: 3px; }


Step 3: Search to keywords <div class='post-footer'> and add the code below just after this keyword
<b:if cond='data:blog.pageType == &quot;item&quot;'>
  <div id='related-posts'>
    <script type='text/javascript'>var ry='<h2>Related Post</h2>';rn='<h2>No Related Post</h2>';rcomment='nhận xét';rdisable='no comments';commentYN='yes';</script>
    <script type='text/javascript'>
    //<![CDATA[
      var dw='';titles=new Array();titlesNum=0;urls=new Array();timeR=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;titlesNum++;break}}}}function removeRelatedDuplicates(){var b=new Array(0);c=new Array(0);e=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];g.length+=1;g[g.length-1]=commentsNum[a]}}urls=b;titles=c;timeR=e;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);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><a href="'+urls[c]+'" rel="nofollow">'+titles[c]+'</a><span>('+timeR[c].substring(8,10)+'/'+timeR[c].substring(5,7)+'/'+timeR[c].substring(0,4)+comments[c]+')</span></li>';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=6;removeRelatedDuplicates();printRelatedLabels('<data:post.url/>');</script>
  </div>
</b:if>

You can change the index maxresults = 6 to change the number of  related post

SHARE THIS
Previous Post
Next Post