how to add this widget
- Go to Blogger Dashboard > Layout > Edit HTML > Download Full Template (for Backup) and click on Expand Widget Templates box.
- Press CTRL + F and search for ]]></b:skin> Add following code BEFORE ]]></b:skin>
<!-- related post -->
.rbbox{border: 1px solid rgb(192, 192, 192);
padding: 5px;
background-color: #f0f0f0;
-moz-border-radius:5px;
margin:5px;
}
.rbbox:hover{background-color: rgb(255, 255, 255);
}
#relpostFs {
border: 1px solid rgb(204, 204, 204);
margin: 0;
padding: 3px 5px;
overflow: auto;
max-height: 200px;
-moz-border-radius:5px;}
<!-- /related post -->
.rbbox{border: 1px solid rgb(192, 192, 192);
padding: 5px;
background-color: #f0f0f0;
-moz-border-radius:5px;
margin:5px;
}
.rbbox:hover{background-color: rgb(255, 255, 255);
}
#relpostFs {
border: 1px solid rgb(204, 204, 204);
margin: 0;
padding: 3px 5px;
overflow: auto;
max-height: 200px;
-moz-border-radius:5px;}
<!-- /related post -->
3. Now look for <data:post.body/>
<!-- related post -->
<b:if cond='data:blog.pageType == "item"'>
<H3>Related Post</H3>
<DIV class='rbbox'>
<DIV id='relpostFs'>
<DIV id='albri'/>
<SCRIPT type='text/javascript'>
var homeUrl3 = "<data:blog.homepageUrl/>";
var maxNumberOfPostsPerLabel = 10;
var maxNumberOfLabels = 10;
maxNumberOfPostsPerLabel = 100;
maxNumberOfLabels = 2;
function listEntries10(json) {
var ul = document.createElement('ul');
var maxPosts = (json.feed.entry.length <= maxNumberOfPostsPerLabel) ?
json.feed.entry.length : maxNumberOfPostsPerLabel;
for (var i = 0; i < maxPosts; i++) {
var entry = json.feed.entry[i];
var alturl;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
alturl = entry.link[k].href;
break;
}
}
var li = document.createElement('li');
var a = document.createElement('a');
a.href = alturl;
if(a.href!=location.href) {
var txt = document.createTextNode(entry.title.$t);
a.appendChild(txt);
li.appendChild(a);
ul.appendChild(li);
}
}
for (var l = 0; l < json.feed.link.length; l++) {
if (json.feed.link[l].rel == 'alternate') {
var raw = json.feed.link[l].href;
var label = raw.substr(homeUrl3.length+13);
var k;
for (k=0; k<20; k++) label = label.replace("%20", " ");
var txt = document.createTextNode(label);
var h = document.createElement('b');
h.appendChild(txt);
var div1 = document.createElement('div');
div1.appendChild(h);
div1.appendChild(ul);
document.getElementById('albri').appendChild(div1);
}
}
}
function search10(query, label) {
var script = document.createElement('script');
script.setAttribute('src', query + 'feeds/posts/default/-/'
+ label +
'?alt=json-in-script&callback=listEntries10');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
}
var labelArray = new Array();
var numLabel = 0;
<b:loop values='data:posts' var='post'>
<b:loop values='data:post.labels' var='label'>
textLabel = "<data:label.name/>";
var test = 0;
for (var i = 0; i < labelArray.length; i++)
if (labelArray[i] == textLabel) test = 1;
if (test == 0) {
labelArray.push(textLabel);
var maxLabels = (labelArray.length <= maxNumberOfLabels) ?
labelArray.length : maxNumberOfLabels;
if (numLabel < maxLabels) {
search10(homeUrl3, textLabel);
numLabel++;
}
}
</b:loop>
</b:loop>
</SCRIPT>
</DIV>
<script type='text/javascript'>RelPost();</script>
</DIV>
<a href="http://chandeepsblogtips.blogspot.com/2011/07/related-posts-widget-for-blogger-based.html" title="Related Posts widget for blogger (based on Labels)"><span class="getfloat">widgets by blogtips</span></a>
</b:if>
<!-- /related post -->
<b:if cond='data:blog.pageType == "item"'>
<H3>Related Post</H3>
<DIV class='rbbox'>
<DIV id='relpostFs'>
<DIV id='albri'/>
<SCRIPT type='text/javascript'>
var homeUrl3 = "<data:blog.homepageUrl/>";
var maxNumberOfPostsPerLabel = 10;
var maxNumberOfLabels = 10;
maxNumberOfPostsPerLabel = 100;
maxNumberOfLabels = 2;
function listEntries10(json) {
var ul = document.createElement('ul');
var maxPosts = (json.feed.entry.length <= maxNumberOfPostsPerLabel) ?
json.feed.entry.length : maxNumberOfPostsPerLabel;
for (var i = 0; i < maxPosts; i++) {
var entry = json.feed.entry[i];
var alturl;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
alturl = entry.link[k].href;
break;
}
}
var li = document.createElement('li');
var a = document.createElement('a');
a.href = alturl;
if(a.href!=location.href) {
var txt = document.createTextNode(entry.title.$t);
a.appendChild(txt);
li.appendChild(a);
ul.appendChild(li);
}
}
for (var l = 0; l < json.feed.link.length; l++) {
if (json.feed.link[l].rel == 'alternate') {
var raw = json.feed.link[l].href;
var label = raw.substr(homeUrl3.length+13);
var k;
for (k=0; k<20; k++) label = label.replace("%20", " ");
var txt = document.createTextNode(label);
var h = document.createElement('b');
h.appendChild(txt);
var div1 = document.createElement('div');
div1.appendChild(h);
div1.appendChild(ul);
document.getElementById('albri').appendChild(div1);
}
}
}
function search10(query, label) {
var script = document.createElement('script');
script.setAttribute('src', query + 'feeds/posts/default/-/'
+ label +
'?alt=json-in-script&callback=listEntries10');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
}
var labelArray = new Array();
var numLabel = 0;
<b:loop values='data:posts' var='post'>
<b:loop values='data:post.labels' var='label'>
textLabel = "<data:label.name/>";
var test = 0;
for (var i = 0; i < labelArray.length; i++)
if (labelArray[i] == textLabel) test = 1;
if (test == 0) {
labelArray.push(textLabel);
var maxLabels = (labelArray.length <= maxNumberOfLabels) ?
labelArray.length : maxNumberOfLabels;
if (numLabel < maxLabels) {
search10(homeUrl3, textLabel);
numLabel++;
}
}
</b:loop>
</b:loop>
</SCRIPT>
</DIV>
<script type='text/javascript'>RelPost();</script>
</DIV>
<a href="http://chandeepsblogtips.blogspot.com/2011/07/related-posts-widget-for-blogger-based.html" title="Related Posts widget for blogger (based on Labels)"><span class="getfloat">widgets by blogtips</span></a>
</b:if>
<!-- /related post -->
Save template and look the changes.
CUSTOMIZATION
---------------------
You can change following parameteres
var maxNumberOfPostsPerLabel = 10;
var maxNumberOfLabels = 10;
maxNumberOfPostsPerLabel = 100;
maxNumberOfLabels = 2;
Hi
ReplyDeleteIs there a way to remove duplicate links being reported?
If I put "maxNumberOfLabels = 3", then I see that same links are getting repeated for each label.
Thanks
When you add two labels in a post then the related post which has that two labels will be repeated. We cannot remove that. :)
DeleteI didnt find in my template
ReplyDeleteExplain please... :)
ReplyDeletehi..my templete got 3 ...so after which one should i paste the code
ReplyDeletetq
got 3 ""
DeleteI cant get you Explain please
DeleteHi Chan Deep, Just curious if you know how to remove the link of the current post which is on the related widget. I already implement a related widget on my blog, just have a problem on this.
ReplyDeletePS: I read from the above comments, that means 2 labels in a post is not advisable on related widget, as it double the entry? Is there any related widget that doesn't behave like that? let me know, thanks... Peace and Blessings, happy blogging.
Sorry Sis, Currently we can't make it with this widget. If I Updated this widget I'll design it as per your wish. ;)
ReplyDeleteThanks for commenting. :)
Hello Chan Deep, I wanna know it's possible to make related post from same label take from new and old link, so be the next post and prev post on same label. If that's possible how to make it? thank you
ReplyDeleteHi Cheri, Sorry It's not possible.
DeleteIs this working in my site dailymediafire.com?
ReplyDeleteIt does not work with my blog: http://www.seoer.com.vn/
ReplyDeleteThanks, it worked perfect, but how to show thumbnails alongwith the post ????
ReplyDeleteHi, thanks for the script! How can I remove label title on the related posts list?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThank you very much. Great article.
ReplyDeleteThanks for sharing, But it not working fine with our blog : http://dungmasterblogs.blogspot.com/2014/02/how-to-add-google-sitemap-to-your.html
ReplyDeleteKindly retry the tutorial step by step :)
DeleteYour work is simply fantastic. But I got some proble with font. My labels are in Vietnamese and the texts rendered like that (Hu%E1%BA%A5n luy%E1%BB%87n)
ReplyDeletehttp://footballmanagervietnam.blogspot.com/2014/03/huan-luyen-vien-chuyen-mon-tot-nhat-football-manager-2014.html
I tried to remove others family font except Arial. But it doesn't change.
Plz show me what to do.
I have the same problem with mr Koo above. Most likely due to font isues. Pls help
ReplyDeleteThanks A Lot...........Works like Butter............
ReplyDelete