Add Related Posts Widget in Blogger / Blogspot Blogs

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

Below are some more related articles to the topic:

Show Post & Comments Count in Blogger / Blogspot Blogs
How to Create a Labels Cloud Widget for Blogger / Blogspot
How To Create Recent Posts Widget For Blogger Blogs
Add Recent Comments Widget in Blogger / Blogspot
How to Add Google Buzz This Button to Blogger/Blogspot Blog Posts

Tags: , , ,

37 Responses to “Add Related Posts Widget in Blogger / Blogspot Blogs”

  1. Ian Edson A. Magpantay 20. Apr, 2009 at 9:27 am #

    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.

  2. Bapun 20. Apr, 2009 at 10:29 am #

    @ 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.

  3. riya 26. Apr, 2009 at 5:11 pm #

    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”.

  4. Bapun 27. Apr, 2009 at 6:16 am #

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

  5. Bewyn 30. Apr, 2009 at 6:53 pm #

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

  6. AgorsGrerge 02. May, 2009 at 7:13 am #

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

  7. Bapun 02. May, 2009 at 3:34 pm #

    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.

  8. Izzy 28. May, 2009 at 11:53 pm #

    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

  9. Izzy 28. May, 2009 at 11:55 pm #

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

  10. iva 03. Jun, 2009 at 6:19 pm #

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

  11. iva 03. Jun, 2009 at 6:55 pm #

    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 :)

  12. kumar 11. Jun, 2009 at 4:08 pm #

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

  13. Paisa Vasool 27. Jun, 2009 at 1:09 am #

    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.

  14. Learn-blogging-tips 28. Jun, 2009 at 5:18 pm #

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

    Keep doing it.

    Thanks for sharing with us.

  15. Thoufeeq 18. Jul, 2009 at 10:49 pm #

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

  16. Bapun 19. Jul, 2009 at 7:18 pm #

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

  17. rex 28. Jul, 2009 at 4:33 pm #

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

  18. Bapun 28. Jul, 2009 at 7:34 pm #

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

  19. winlin 06. Aug, 2009 at 1:39 am #

    Very nice thank you

  20. imran 09. Sep, 2009 at 11:06 am #

    thanxx dude

  21. Naser 03. Oct, 2009 at 9:42 pm #

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

  22. winlin 19. Oct, 2009 at 1:50 am #

    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.

  23. Awais 04. Nov, 2009 at 11:37 pm #

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

  24. danielle 24. Dec, 2009 at 3:17 am #

    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?

  25. Bapun 30. Dec, 2009 at 5:38 pm #

    @ 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.

  26. Jatt 31. Dec, 2009 at 1:09 pm #

    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?

  27. Bapun 31. Dec, 2009 at 5:12 pm #

    @ 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.

  28. ceejay 04. Jan, 2010 at 4:44 pm #

    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.

  29. webgeeks 25. Apr, 2010 at 11:23 pm #

    it is working for me thanks

  30. moli 08. May, 2010 at 9:10 am #

    I tried the first method. It worked great. Just I would like to place the related posts on the right side bar. How would I do that?

    • Bapun 08. May, 2010 at 9:17 am #

      Moli, you just need to add the related posts code to the right sidebar and that’s it.

  31. Brian M. Connole @ i-Blogger 20. May, 2010 at 1:00 am #

    For some reason when I tried the second method nothing showed up. Could you help, I would like to use this widget.

    Thanks,
    Brian M. Connole

    • Bapun 20. May, 2010 at 12:19 pm #

      Brian, the second step is quite easy and works well. Have you followed all steps correctly?

  32. ISHAQUE 29. May, 2010 at 2:01 am #

    Its not showing for me too, i have tried the 2nd step.

    thanx

  33. Lindsay 21. Jun, 2010 at 1:01 pm #

    I followed method #2 and this message appears below my blog posts:
    Could not find the possible script tags, you can only include BRPS client brps.js script once.

    Can you help me out? Thanks!
    Lindsay

    PS–I tried method 1 but got the error message commented on above–”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”.”

  34. Kenan Sevindik 02. Jul, 2010 at 5:10 am #

    thanks a lot, method 1 worked for me too…

  35. PaulsHealthBlo.com 21. Jul, 2010 at 4:40 am #

    The “Related Posts” titled showed up, but nothing else did. No related posts links at all. I used method number two.

    I wonder if this widget is compatible with Josh Peterson’s “Simple” Blogger template.

    Thanks,

    Paul

Leave a Reply