Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Related Posts for Blogger

This is one of the most wanted widgets on Blogger!It's very nice for your blog to show your related posts on your Blogger blog so your visitors can be easily navigate from one post to another.Off course this is NOT necessary and is up to your choice if you think your blog needs it or not.


*Updated!

1) Log on your dashboard

2) Save your template!

3) Get to "Edit Html" & expand Widget

4) Find this code:
</head>


5) Replace it with this code:
<!--Related Posts Scripts and Styles Start-->
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<style>
#related-posts {
float:center;
text-transform:none;
height:100%;
min-height:100%;
padding-top:5px;
padding-left:5px;
}
#related-posts .widget{
padding-left:6px;
margin-bottom:10px;

}
#related-posts .widget h2, #related-posts h2{
font-size: 1.6em;
font-weight: bold;
color: black;
font-family: Georgia, &#8220;Times New Roman&#8221;, Times, serif;
margin-bottom: 0.75em;
margin-top: 0em;
padding-top: 0em;
}
#related-posts a{
color:blue;
}
#related-posts a:hover{
color:blue;
}
#related-posts ul{
list-style-type:none;
margin:0 0 0px 0;
padding:0px;
text-decoration:bold;
font-size:15px;
text-color:#000000
}
#related-posts ul li{
background:transparent url(http://2.bp.blogspot.com/_u4gySN2ZgqE/SnZhv_C6bTI/AAAAAAAAAl4/Rozt7UhvgOo/s200/greentickbullet.png) no-repeat ;
display:block;
list-style-type:none;
margin-bottom: 13px;
padding-left: 30px;
padding-top:0px;}
</style>
<script type='text/javascript'>
var relatedpoststitle="Related Posts";
</script>
<script type='text/javascript'>
//<![CDATA[
//<![CDATA[
var relatedTitles = new Array();
var relatedTitlesNum = 0;
var relatedUrls = new Array();
function related_results_labels(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
relatedTitles[relatedTitlesNum] = entry.title.$t;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
relatedUrls[relatedTitlesNum] = entry.link[k].href;
relatedTitlesNum++;
break;
}
}
}
}
function removeRelatedDuplicates() {
var tmp = new Array(0);
var tmp2 = new Array(0);
for(var i = 0; i < relatedUrls.length; i++) {
if(!contains(tmp, relatedUrls[i])) {
tmp.length += 1;
tmp[tmp.length - 1] = relatedUrls[i];
tmp2.length += 1;
tmp2[tmp2.length - 1] = relatedTitles[i];
}
}
relatedTitles = tmp2;
relatedUrls = tmp;

}
function contains(a, e) {
for(var j = 0; j < a.length; j++) if (a[j]==e) return true;
return false;
}
function printRelatedLabels() {
for(var i = 0; i < relatedUrls.length; i++)
{
if(relatedUrls[i]==currentposturl)
{
relatedUrls.splice(i,1)
relatedTitles.splice(i,1)

}
}
var r = Math.floor((relatedTitles.length - 1) * Math.random());
var i = 0;

if(relatedTitles.length>1) document.write('<h2>'+relatedpoststitle+'</h2>');
document.write('<ul>');
while (i < relatedTitles.length && i < 20 && i<maxresults) {
document.write('<li><a href="' + relatedUrls[r] + '">' + relatedTitles[r] + '</a></li>');
if (r < relatedTitles.length - 1) {
r++;
} else {
r = 0;
}
i++;
}
document.write('</ul>');
}
//]]>


</script>
</b:if>
<!--Related Posts Scripts and Styles End-->
</head>


6) Now,there is several codes to look in your template to complete this widget.
Search for:
<div class='post-footer-line post-footer-line-1'>

OR
<p class='post-footer-line post-footer-line-1'>

OR
<p><data:post.body/></p> 

OR
<data:post.body/>


(If you have the "Read more" hack you need to add the following code AFTER that.)

7)Add this code after whichever of the codes you found.NOTE: If you using Social Bookmarkings after each post as i do,past the code below that.

<!-- Related Posts 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>
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<script expr:src='&quot;/feeds/posts/default/-/&quot; + data:label.name + &quot;?alt=json-in-script&amp;callback=related_results_labels&amp;max-results=6&quot;' type='text/javascript'/></b:if></b:loop>
<script type='text/javascript'>
var currentposturl=&quot;<data:post.url/>&quot;;
var maxresults=5;
removeRelatedDuplicates(); printRelatedLabels();
</script>
</div>
</b:if>
<!-- Related Posts Code End-->




Save & preview.

*Customize.
Some tips to customize it as you want to fit better on your site.The customization can be done from the first part of the code.

a) Change the title
var relatedpoststitle="Related Posts";


b) Change the color and mouseover color
#related-posts a{
color:blue;
}
#related-posts a:hover{
color:blue;


c) Change the Title color
color: black;


d) Change font size and color
font-size:15px;
text-color:#000000


e) Change the "Green Tick" icon. Find (Ctrl+F) this URL and change it with your image url.NOTE: Maximum 24x24
http://2.bp.blogspot.com/_u4gySN2ZgqE/SnZhv_C6bTI/AAAAAAAAAl4/Rozt7UhvgOo/s200/greentickbullet.png


f) To change the number of the displaying "Related posts" look on the second part of code and change this number
var maxresults=5;


g) Proceed like we did in more changes in the CSS code.Just don't forget to save your template first!



This post first appeared on Blogger Widgets ::blocoon::, please read the originial post: here

Share the post

Related Posts for Blogger

×

Subscribe to Blogger Widgets ::blocoon::

Get updates delivered right to your inbox!

Thank you for your subscription

×