Related Posts plays an important role in interlinking blog post to get visitors to the posts with related topics.To make your visitors to visit your other related posts you have to make it visible for your readers.This widget uses a little of JavaScript to combine the posts present on your blog.You can also customized this widget to see it running below every posts.So follow these simple steps on how to add it in blogger.
- Go to Blogger Dashboard>Design>Edit HTML.
- Just above the </head> tag add the following code,
<!--RelatedPostsStarts-->
<style>
#related-posts {
float :
left
;
width
:
550px
;
margin-top
:
0px
;
margin-
left
:
5px
;
font :
11px
Verdana
;
padding
:
5px
;
}
#related-posts .widget {
list-style-type :
none
;
margin :
5px
0
5px
0
;
padding :
0
;
}
#related-posts .widget h
2
, #related-posts h
2
{
color :
#940f04
;
font-size :
20px
;
font-weight :
normal
;
margin :
5px
7px
0
;
padding :
0
0
5px
;
}
#related-posts a {
color :
#054474
;
font-size :
11px
;
text-decoration :
none
;
}
#related-posts a:hover {
color :
#0080ff
;
text-decoration :
none
;
}
#related-posts ul {
list-style
:
none
;
padding
:
0px
!important
;
}
#related-posts ul li {
background
:
transparent
url
(http://
3
.bp.blogspot.com/_
7
wsQzULWIwo/SuM
3
oFg
5
zlI/AAAAAAAACHo/n
5
UluB
5
ugMI/s
400
/
255
.gif)
no-repeat
scroll
0px
6px
;
margin
:
0.3em
0
!important
;
padding
:
0
0
0.8em
20px
;
line-height :
2em
;
border-bottom
:
1px
dotted
#cccccc
;
}
#related-posts ul li:hover{
background
:
transparent
url
(http://
2
.bp.blogspot.com/_
7
wsQzULWIwo/SuM
3
oYoTkRI/AAAAAAAACHw/Dig
1
etGrcpY/s
400
/
251
.gif)
no-repeat
scroll
0px
6px
!important
;
}
</style>
<script language=
'JavaScript'
>
//<![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 tmp
2
= 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];
tmp
2
.length +=
1
;
tmp
2
[tmp
2
.length -
1
] = relatedTitles[i];
}
}
relatedTitles = tmp
2
;
relatedUrls = tmp;
}
function contains(a, e) {
for(var j =
0
; j < a.length; j++) if (a[j]==e) return true;
return false;
}
function printRelatedLabels() {
var r = Math.floor((relatedTitles.length -
1
) * Math.random());
var i =
0
;
document.write(
'<ul>'
);
while (i < relatedTitles.length && i <
6
) {
document.write(
'<li><a href="'
+ relatedUrls[r] +
'">'
+ relatedTitles[r] +
'</a></li>'
);
if (r < relatedTitles.length -
1
) {
r++;
} else {
r =
0
;
}
i++;
}
document.write(
'</ul>'
);
document.write(
'<a rel="dofollow" href="http://www.mybloggertips.com" style="float:right;font-size:10px;">Blogger Widgets</a></font>'
);
}
//]]>
</script>
<!--RelatedPostsStops-->
- Now find <data:post.body/> Use CTRL+F to find the code
- Add the following code just below the above code,
<div id=
'related-posts'
>
<font color=
'<span style="color: #ffcc00;">#289728</span>'
face=
'Arial'
size=
'4'
><b>Related Tricks:</b></font><font color=
'#ffffff'
><b:loop values=
'data:post.labels'
var=
'label'
><data:label.name/><b:if cond=
'data:label.isLast != "true"'
>,</b:if><b:if cond=
'data:blog.pageType == "item"'
>
<script expr:src=
'"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels&max-results=5"'
type=
'text/javascript'
/></b:if></b:loop> </font>
<script type=
'text/javascript'
> removeRelatedDuplicates(); printRelatedLabels();
</script>
</div>
Customize Related Posts WidgetSo here’s the customization of related posts widget,- You change the color of Related Tricks which is “#289728″
- You can change the Text “Related Tricks” to any other you want.
- If you want to display this widget only on post pages then add this tag at the starting of the above code,
<b:if cond=
'data:blog.pageType == "item"'
>
and the below code at the end of the code above,
</b:if>
See the Example Here!Lets say if you want to add this widget only on post pages then add the following code just below <data:post.body/>
<b:if cond=
'data:blog.pageType == "item"'
><div id=
'related-posts'
>
<font color=
'<span style="color: #ffcc00;">#289728</span>'
face=
'Arial'
size=
'4'
><b>Related Tricks:</b></font><font color=
'#ffffff'
><b:loop values=
'data:post.labels'
var=
'label'
><data:label.name/><b:if cond=
'data:label.isLast != "true"'
>,</b:if><b:if cond=
'data:blog.pageType == "item"'
>
<script expr:src=
'"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels&max-results=5"'
type=
'text/javascript'
/></b:if></b:loop> </font>
<script type=
'text/javascript'
> removeRelatedDuplicates(); printRelatedLabels();
</script>
</div></b:if>
Now it is your turn!It’s your turn to help us grow.If this information seems useful to you kindly share your views by commenting here and like us on Facebook to get more updates.If you want to get news directly in your inbox just subscribe to our RSS feeds.Don’t forget to share Please.
- Go to Blogger Dashboard>Design>Edit HTML.
- Just above the </head> tag add the following code,
<!--RelatedPostsStarts--> <style> #related-posts { float : left ; width : 550px ; margin-top : 0px ; margin- left : 5px ; font : 11px Verdana ; padding : 5px ; } #related-posts .widget { list-style-type : none ; margin : 5px 0 5px 0 ; padding : 0 ; } #related-posts .widget h 2 , #related-posts h 2 { color : #940f04 ; font-size : 20px ; font-weight : normal ; margin : 5px 7px 0 ; padding : 0 0 5px ; } #related-posts a { color : #054474 ; font-size : 11px ; text-decoration : none ; } #related-posts a:hover { color : #0080ff ; text-decoration : none ; } #related-posts ul { list-style : none ; padding : 0px !important ; } #related-posts ul li { background : transparent url (http:// 3 .bp.blogspot.com/_ 7 wsQzULWIwo/SuM 3 oFg 5 zlI/AAAAAAAACHo/n 5 UluB 5 ugMI/s 400 / 255 .gif) no-repeat scroll 0px 6px ; margin : 0.3em 0 !important ; padding : 0 0 0.8em 20px ; line-height : 2em ; border-bottom : 1px dotted #cccccc ; } #related-posts ul li:hover{ background : transparent url (http:// 2 .bp.blogspot.com/_ 7 wsQzULWIwo/SuM 3 oYoTkRI/AAAAAAAACHw/Dig 1 etGrcpY/s 400 / 251 .gif) no-repeat scroll 0px 6px !important ; } </style> <script language= 'JavaScript' > //<![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 tmp 2 = 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]; tmp 2 .length += 1 ; tmp 2 [tmp 2 .length - 1 ] = relatedTitles[i]; } } relatedTitles = tmp 2 ; relatedUrls = tmp; } function contains(a, e) { for(var j = 0 ; j < a.length; j++) if (a[j]==e) return true; return false; } function printRelatedLabels() { var r = Math.floor((relatedTitles.length - 1 ) * Math.random()); var i = 0 ; document.write( '<ul>' ); while (i < relatedTitles.length && i < 6 ) { document.write( '<li><a href="' + relatedUrls[r] + '">' + relatedTitles[r] + '</a></li>' ); if (r < relatedTitles.length - 1 ) { r++; } else { r = 0 ; } i++; } document.write( '</ul>' ); document.write( '<a rel="dofollow" href="http://www.mybloggertips.com" style="float:right;font-size:10px;">Blogger Widgets</a></font>' ); } //]]> </script> <!--RelatedPostsStops--> |
- Now find <data:post.body/> Use CTRL+F to find the code
- Add the following code just below the above code,
<div id= 'related-posts' > <font color= '<span style="color: #ffcc00;">#289728</span>' face= 'Arial' size= '4' ><b>Related Tricks:</b></font><font color= '#ffffff' ><b:loop values= 'data:post.labels' var= 'label' ><data:label.name/><b:if cond= 'data:label.isLast != "true"' >,</b:if><b:if cond= 'data:blog.pageType == "item"' > <script expr:src= '"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels&max-results=5"' type= 'text/javascript' /></b:if></b:loop> </font> <script type= 'text/javascript' > removeRelatedDuplicates(); printRelatedLabels(); </script> </div> |
<b:if cond= 'data:blog.pageType == "item"' > |
</b:if> |
<b:if cond= 'data:blog.pageType == "item"' ><div id= 'related-posts' > <font color= '<span style="color: #ffcc00;">#289728</span>' face= 'Arial' size= '4' ><b>Related Tricks:</b></font><font color= '#ffffff' ><b:loop values= 'data:post.labels' var= 'label' ><data:label.name/><b:if cond= 'data:label.isLast != "true"' >,</b:if><b:if cond= 'data:blog.pageType == "item"' > <script expr:src= '"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels&max-results=5"' type= 'text/javascript' /></b:if></b:loop> </font> <script type= 'text/javascript' > removeRelatedDuplicates(); printRelatedLabels(); </script> </div></b:if> |