Monday, December 29, 2014

nRelate Alternatives: Related Post Widget for Blogger with Hover Effect.

0 Comments
nRelate AlternativenRelate is one of the popular Related Post Widget used by bloggers. I was also using it on some of my blogs. But recently, it was announced that it will stop serving recommendations on December 31, 2014. All nRelate services including their customer facing dashboards will be terminated, and we have sign up for an alternative discovery platform by the end of December.

So keeping this in mind, I’ve prepared another code for related articles widget. It is very much clean and very easy to use. No scripts hosted on third party servers is used, so it will lasts forever without any hiccup.
Related Post Widget


The lookup of this widget is  somewhat like nRelate’s “Default” theme style as shown snapshot in the right figure.

In future, I’ll  provide you more theme as like provided by nRelate. So keep in touch for further updates.



How to Install Related Post Widget at Blogger.com?

Step 1. First of all, remove nRelate code for related post posts, if have not done so.

Step2. Make a backup of your current template. This will help you get previous look if something wrong takes place with implementation. If you don’t know how to make backup of blogger template, you can use this “Template>> Backup/Restore”.

Step 3. After login to Blogger Dashboard, Go to “Template” and then click “Edit Html”. Click anywhere inside the template code area, then press CTRL + F keys to open search box. Search for following code:
</head>

Step 4. Just above closing head tag, paste the following code:
<!-- Related post widget script starts -->

<script type='text/javascript'>
var defaultnoimage=&quot;http:https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZmkJDpQ4gL8igtGV3EZdfQcWoQUwvhRnJ7cj8HvI8O3R5aQLUGHARkjqVeMzJ18pK6oEsOkGVDVfGCtARGvYGKn1Ecg5aV8S8U3ScthWEalHZd7gNlWNSnbgeDkdi1UoqAgpWItmyTQY/s400/noimage.png&quot;;
var maxresults=5;
var splittercolor=&quot;#fff&quot;;
var relatedpoststitle=&quot;Related Posts&quot;;
</script>

&lt;script type=&#39;text/javascript&#39;&gt;
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&lt;json.feed.entry.length;i++){var entry=json.feed.entry[i];relatedTitles[relatedTitlesNum]=entry.title.$t;try{thumburl[relatedTitlesNum]=entry.media$thumbnail.url}catch(error){s=entry.content.$t;a=s.indexOf(&quot;&lt;img&quot;);b=s.indexOf(&quot;src=\&quot;&quot;,a);c=s.indexOf(&quot;\&quot;&quot;,b+5);d=s.substr(b+5,c-b-5);if((a!=-1)&amp;&amp;(b!=-1)&amp;&amp;(c!=-1)&amp;&amp;(d!=&quot;&quot;)){thumburl[relatedTitlesNum]=d}else{if(typeof(defaultnoimage)!==&#39;undefined&#39;){thumburl[relatedTitlesNum]=defaultnoimage}else{thumburl[relatedTitlesNum]=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZmkJDpQ4gL8igtGV3EZdfQcWoQUwvhRnJ7cj8HvI8O3R5aQLUGHARkjqVeMzJ18pK6oEsOkGVDVfGCtARGvYGKn1Ecg5aV8S8U3ScthWEalHZd7gNlWNSnbgeDkdi1UoqAgpWItmyTQY/s400/noimage.png&quot;}}}if(relatedTitles[relatedTitlesNum].length&gt;65){relatedTitles[relatedTitlesNum]=relatedTitles[relatedTitlesNum].substring(0,65)+&quot;...&quot;}for(var k=0;k&lt;entry.link.length;k++){if(entry.link[k].rel==&#39;alternate&#39;){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&lt;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&lt;a.length;j++){if(a[j]==e){return true}}return false}function printRelatedLabels_thumbs(current){var splitbarcolor;if(typeof(splittercolor)!==&#39;undefined&#39;){splitbarcolor=splittercolor}else{splitbarcolor=&quot;#d4eaf2&quot;}for(var i=0;i&lt;relatedUrls.length;i++){if((relatedUrls[i]==current)||(!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&gt;0){document.write(&#39;&lt;h2&gt;&#39;+relatedpoststitle+&#39;&lt;/h2&gt;&#39;)}document.write(&#39;&lt;div style=&quot;clear: both;&quot;/&gt;&#39;);while(i&lt;relatedTitles.length&amp;&amp;i&lt;20&amp;&amp;i&lt;maxresults){document.write(&#39;&lt;div&gt;&lt;a style=&quot;display:inline-block;float:left&quot;&#39;);if(i!=0)document.write(&#39;&#39;+splitbarcolor+&#39;;&quot;&#39;);else document.write(&#39;&quot;&#39;);document.write(&#39; href=&quot;&#39;+relatedUrls[r]+&#39;&quot;&gt;&lt;img style=&quot;&quot; src=&quot;&#39;+thumburl[r]+&#39;&quot;/&gt;&lt;br/&gt;&lt;div style=&quot;&quot;&gt;&#39;+relatedTitles[r]+&#39;&lt;/div&gt;&lt;/a&gt;&lt;/div&gt;&#39;);i++;if(r&lt;relatedTitles.length-1){r++}else{r=0}}document.write(&#39;&lt;/div&gt;&#39;);relatedUrls.splice(0,relatedUrls.length);thumburl.splice(0,thumburl.length);relatedTitles.splice(0,relatedTitles.length)}
&lt;/script&gt;

<!-- Related post widget script ends –>

  • In the above code, you can change number of related articles by changing value “maxresults=5;” as per your requirement.

  • To change heading of the widget, replace code highlighted in Marroon color such as with “You might be interested in”, “You may also like”, “Recommended Articles”, etc.

Step 5. Paste the following code, where you want to appear the related articles widget:
<!-- Related Posts with Thumbnails Code Start-->
<div class='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/summary/-/&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'>
removeRelatedDuplicates_thumbs();
printRelatedLabels_thumbs(&quot;<data:post.url/>&quot;);
     </script>
</div><div style="font-size: 10px; vertical-align: bottom; float: right"><a href="http://blogger-hatchery.blogspot.com/2014/12/nrelate-alternatives-related-post.html" target="_blank">Get this widget</a></div>
<!-- Related Posts with Thumbnails Code End—>

For example, search for the following code:
<div class='post-footer'>

and paste just above this code. You may find this code multiple times in template, but you should stick to last one. If this code doesn’t work, then try with other same codes above one by one.

Step 6. Now comes the styling part. Search the following code:
]]></b:skin>

and paste following code just above previous code:
.related-posts {
  float:center;
  text-transform:none;
  height:100%;
  min-height:100%;
  margin-top:15px;
  padding-left:5px;
}
.related-posts a img {
  width: 110px;
  height: 110px;
  padding: 2px; border-radius: 5px;
  border: 1px solid #CFCFCF!important;
}
.related-posts a {
  padding: 10px;
  font-size: 13px;
  border: 1px solid #EEEEEE;
  border-radius: 5px;
  overflow: hidden;
  margin-left: 4px;
  margin-right: 4px;
  margin-top: 5px;
  margin-bottom: 5px;
  width: 115px;
  background: #ffffff;
  min-height: 210px;
  font-family: sans-serif;
  font-weight: 700;
  line-height: 140%;
  text-align: left;
}
.related-posts a:hover {
  background: #44B329;
  color: #fff;
  border: 1px solid #44B329;
}
.related-posts div {
  line-height: normal;
  display:inline-block;
}

Step 7. Now you have done. The related posts widget will appear in your website.

Customization:

  1. Change thumbnail dimensions by changing value in green highlighted code in Step 6. But with this, you must also change width: 115px;  in the same step to “your thumbnail width + 5 px” to match the changes.

  2. Change the code highlighted in red color to change background of widget.

  3. Change margins in Yellow highlighted codes to change margin between two related posts to fit all the related posts (in present case 6) in the widget in fill in entire width of your website.

I am sure that this posts have helped you. You should share and subscribe for further updates and new themes for the widget. 
In case of any inquiry please use comment box.
Please share...
Subscribe us...

Delivered by FeedBurner

Random Posts

No comments:

Post a Comment