Recommended: Fix Windows Errors and Improve PC Performance

Add Related Posts Widget in Blogger / Blogspot Blogs

Posted by Bapun 30 March, 2009

Related posts widget appear just below your blogger posts and allow your visitors to navigate through similar posts from your blog. This is also a method to get more page views and keep your visitor on your site for a longer period of time. Remember that this plugin shows the related posts only, it uses some simple algorithm to pull out similar posts from your blog. If you are comfortable with HTML editing, you can add any attractive style to the related posts plugin by editing the CSS code. So, this blogger hack is loaded with performance and style.

How to install Related Posts Blogger Widget To Your Blogspot Blog :

We can add related posts plugin to your blogger blog in two methods. Let me guide you with those two methods one by one. But remember to take a backup of your existing template before editing and adding related posts widget. (How to take online backup of Blogger blogs?)

First Method :

  1. Log in to your blogger Dashboard.
  2. Navigate to your blog’s Layout >> Edit HTML
  3. Expand your widget by clicking on Expand widget templates
  4. Find the following code in your template. (Press Ctrl+F to make a search)
  5. <p><data:post.body/></p>
  6. Now paste the following code just below the above code.
  7. <b:if cond=’data:blog.pageType == “item”‘>
    <div class=’similiar’>
    <!– *****************http://blogger.com*****Jan,2007****************** –>
    <!– *****************Related Articles by Labels – Take Two****************** –>

    <!–

    1. Now, users don’t need to change anything to use this widget. just copy and paste, and done!
    2. The current article will also be listed, now it’s no more.
    –>

    <div class=’widget-content’>
    <h3>Related Posts by Categories</h3>
    <div id=’data2007′/><br/>
    <div id=’SolidBlogger’>
    Related Posts Widget by <u><a href=’http://solidblogger.com’>SolidBlogger</a></u>
    </div>
    <script type=’text/javascript’>

    var homeUrl3 = &quot;<data:blog.homepageUrl/>&quot;;
    var maxNumberOfPostsPerLabel = 4;
    var maxNumberOfLabels = 10;

    maxNumberOfPostsPerLabel = 5;
    maxNumberOfLabels = 3;

    function listEntries10(json) {
    var ul = document.createElement(&#39;ul&#39;);
    var maxPosts = (json.feed.entry.length &lt;= maxNumberOfPostsPerLabel) ?
    json.feed.entry.length : maxNumberOfPostsPerLabel;
    for (var i = 0; i &lt; maxPosts; i++) {
    var entry = json.feed.entry[i];
    var alturl;

    for (var k = 0; k &lt; entry.link.length; k++) {
    if (entry.link[k].rel == &#39;alternate&#39;) {
    alturl = entry.link[k].href;
    break;
    }
    }
    var li = document.createElement(&#39;li&#39;);
    var a = document.createElement(&#39;a&#39;);
    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 &lt; json.feed.link.length; l++) {
    if (json.feed.link[l].rel == &#39;alternate&#39;) {
    var raw = json.feed.link[l].href;
    var label = raw.substr(homeUrl3.length+13);
    var k;
    for (k=0; k&lt;20; k++) label = label.replace(&quot;%20&quot;, &quot; &quot;);
    var txt = document.createTextNode(label);
    var h = document.createElement(&#39;b&#39;);
    h.appendChild(txt);
    var div1 = document.createElement(&#39;div&#39;);
    div1.appendChild(h);
    div1.appendChild(ul);
    document.getElementById(&#39;data2007&#39;).appendChild(div1);
    }
    }
    }
    function search10(query, label) {

    var script = document.createElement(&#39;script&#39;);
    script.setAttribute(&#39;src&#39;, query + &#39;feeds/posts/default/-/&#39;
    + label +
    &#39;?alt=json-in-script&amp;callback=listEntries10&#39;);
    script.setAttribute(&#39;type&#39;, &#39;text/javascript&#39;);
    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 = &quot;<data:label.name/>&quot;;

    var test = 0;
    for (var i = 0; i &lt; labelArray.length; i++)
    if (labelArray[i] == textLabel) test = 1;
    if (test == 0) {
    labelArray.push(textLabel);
    var maxLabels = (labelArray.length &lt;= maxNumberOfLabels) ?
    labelArray.length : maxNumberOfLabels;
    if (numLabel &lt; maxLabels) {
    search10(homeUrl3, textLabel);
    numLabel++;
    }
    }
    </b:loop>
    </b:loop>
    </script>
    </div>

    </div>
    </b:if>

  8. Check out the below screenshot for the correct implementation of the code.
  9. related posts blogger

  10. Save your template to see that you have just added the related posts plugin to your blogger blog.
  11. You are done.

Second Method :

Unlike the above manual method, second method allows you to add related posts widget with a single click. Follow the below steps.

  1. Click on the below button.
  2. Select the blog in which you want to install this widget.
  3. Give a proper title to this widget. You may want to name it as “Related Posts“.
  4. Click on Add Widget to get this widget added to your blogger blog’s sidebar.
  5. You can change this widget’s location by placing it just below the blog post’s widget. Now it will be displayed in Blog post >> Comments >>  Related Posts order.
  6. Now if you want to add this just below the blog post and above  comments, follow the below steps.
  7. Navigate to Layout >> Edit HTML >> Expand Widget Templates and search for the below code.
  8. <div class='post-footer-line post-footer-line-3'/>
    ...
    </div>
  9. Add the following code just below the above code in your template.
  10. <div id='related_posts'/>
  11. Now the whole code should look like the below screenshot :
  12. add related posts widget to blogger

  13. Save your template at this point.
  14. Now again search for </body> tag in your template. You can also scroll down to end of your template, it’s located there.
  15. Add the following codes just above that </body> tag.
  16. <script src='http://www.google.com/jsapi'/>
    <script src='http://brps.appspot.com/brps.js' type='text/javascript'/>
  17. Save your template and you are done.

These are the methods to add Related posts blogger widget on your blogspot blog. You can follow either the first or the second method to get the related posts showing just below your blogger posts.

Also Read : How to Add Google Analytics Code To Your Blogger Blog

We will send you some more information related to Add Related Posts Widget in Blogger / Blogspot Blogs

Categories : Blogspot Tags : , , ,

Comments
April 20, 2009

Thank you for this widget. However, is there a way that we can limit the number of related posts to only a certain number (e.g. Five). The thing is, if you have many related labels on your post, it takes to long to load.

April 20, 2009

@ Ian : Yes, you can configure no of related post. Simply edit the following code in your template with your values and you are done.

maxNumberOfPostsPerLabel = 100;
maxNumberOfLabels = 3;

NOTE : Earlier code in this post was showing 100 related posts :P It’s edited now to show 5 posts from each label and 3 labels maximum.

Posted by Bapun
April 26, 2009

i am getting this error

Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: Open quote is expected for attribute “{1}” associated with an element type “cond”.

Posted by riya
April 27, 2009

@ Riya : Can you tell me if you followed the first or second method, so that I can guide you further.

Posted by Bapun
April 30, 2009

ya i did the above procedure but when in searched the code its not found pls help me

Posted by Bewyn
May 2, 2009

Thanks. i love this site :) Keep posting such lovely articles.

Posted by AgorsGrerge
May 2, 2009

Bewyn : I’m not getting you! What you couldn’t find? The code is above, simply copy it and paste in your template. That’s it. Be specific with your problem, so that I can help you further.

Posted by Bapun
May 28, 2009

These seemed to be a very good breakdown, but I can’t seem to get it working. Is there anyway that I could get some help? It is saying that the code is incorrect

Posted by Izzy
May 28, 2009

Oh, I’m getting the same error as riya. and I used method 1

Posted by Izzy
June 3, 2009

thank you so much. It worked perfectly well! :)

Posted by iva
June 3, 2009

hi,

i have successfully added the widget on my website (http://goodlorax.blogspot.com); but when I tried to put it on my other blog (http://kivaa.blogspot.com/), using method #2, I encounter a little problem.

I couldn’t find the
; because I only have .

I already paste it below as ur instruction, but doesn’t seem to work .. I tried to change the <p class to <div class (I don’t know what it means), but didn’t work also.

Any advice? Anyway I tried using your #1 method but didn’t work also .. :(

Heeeeeeeellppp !! :)

Thank you so much :)

Posted by iva
June 11, 2009

its showing only 25 posts. im having 100 related posts how to show them ??

Posted by kumar
June 27, 2009

Thanks a lot this really helped me. I initially had linkedwithin and it was making the pages look a little off. Now with this it looks nice and neat.

Posted by Paisa Vasool
June 28, 2009

I do really liked your blog that looks very simple and neat…

Keep doing it.

Thanks for sharing with us.

July 18, 2009

When I search for this line , it is not in my template code.

Posted by Thoufeeq
July 19, 2009

@ Thoufeeq : Expand the template first and then search for the code.

Posted by Bapun
July 28, 2009

It did not work for my blog….get error sign…

Posted by rex
July 28, 2009

@ Rex : What’s the error message? I can assist you further if you provide me the details.

Posted by Bapun
August 6, 2009

Very nice thank you

Posted by winlin
September 9, 2009

thanxx dude

Posted by imran
October 3, 2009

hello i have crystal blue template. This code does not work for my template please give a code starting with

Posted by Naser
October 19, 2009

hii solidblogger,
thanks for this nice blog I really appreciate your great work .

The new issue about this “related post widget,
the programmer start blocking all blogs, that have illegal content, http://thebrps.blogspot.com/

The author of BRPS may be blocking your blogs from

* Copyright infringement (If your blogs have links to any illegal downloads, directly or indirectly, upload by youself or not, please DO NOT use BRPS. Otherwise, your blogs will be BLOCKED for sure),
* Hate against a protected group,
* Adult or pornographic images,
* Promotion of dangerous and illegal activity,
* Content facilitating phishing or account hijacking,
* Impersonated user identity, or
* Abuse this service.

and it will appear this message instead of showing related posts

Related Posts :
This blog is blocked from using Blogger Related Posts Service. If you are the blog owner and believe this blocking is a mistake, please contact the author of BRPS.

Posted by winlin
November 4, 2009

1st method is not working because i already add read more coding to the blog

Posted by Awais
December 24, 2009

Is there a way to specify the post by name you want displayed? Example: I only want posts with the word ‘Giveaways’ to display in the sidebar?

Posted by danielle
December 30, 2009

@ Danielle : I don’t think there is any such service to filter words and show the resulting posts. You may add a specific label (such as : Giveaway) to such posts and then display the posts under that label in the sidebar.

Posted by Bapun
December 31, 2009

This code does not work for me..
I’m getting this error message..

Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: Open quote is expected for attribute “{1}” associated with an element type “cond”.

I followed the 1st method..
Do this error because i already add read more code to my blog?
Please help me?

Posted by Jatt
December 31, 2009

@ Jatt : You could have done something wrong during implementation as it has noting to do with the “read more” hack. Send me your template so that I can look into that. Use “Contact Us” form.

Posted by Bapun
January 4, 2010

thanks a lot, i was having problem locating the first method.
i mean i don’t think there is this code in my template
< data. post:body….
in my template…
where can i locate it.. should in case i want to use the code some time.
thanks again.

Posted by ceejay
Leave a comment

(required)

(required)


Top incoming search terms for this post