Displaying a related posts is a smart way for keeping your site visitors around. and you may have seen other Related Posts Widgets out there.. but this one will be Easier and Smarter.
check features list:
- Easier : since All of the work is(has to be) done on the client side, You will not need to modify your template at all. widget will read post tags that blogger already display with each post.
- Smarter : Cause This widget will list the top related 5(or more) posts sorted by relevancy!
Top relevant posts are the posts that have more tags in common with the current post. - More Optimized: Will only use summary feeds instead of querying default feeds that return full contents!
- This widget also can work as a recent posts widget when there is no tags to aggregate.
- Can be also used to get related posts from another blogspot blog. And in that case you don't have to run it on a blogspot!
- A fixed list of tags can be used to aggregate.
- It can display loading text or icon until widget is loaded.
- Related posts list can be styled based on relevancy!
- You can specify either to load widget on document ready or on window load.
- Widget will be attached to container specified or it will be placed where you made the JavaScript call.
This is the complete options table
Every variable is optional. exclude it to have default value.
If you want to understand code behind this widget, check [Code behind : A Smarter Related Posts widget for Blogger].
Typical Usage #1
To display related links at the end of every post. copy this code into a new HTML/Javascript widget and place at the bottom of the post or at the footer in the page elements section.
Widget uses jQuery v1.3.2, If you already included jQuery into your blog. no need to do it again.
[containerSelector : 'div.post-body'] is the default container selector of your post body as output by blogger. which means find 'div' tag with class="post-body" if you unlikely modified it; find your new selector.
* Note that:
-you should host widget javascript file on your own, Google code has no problem hosting the project javascript files.
- You may also try Fileden as it is only file hosting I know that would give you a direct-link (A Must for javascript to work)or you can just upload it to your Google pages(phasing out).
But keep the jQuery URL as is, since Google hosts jQuery(and others) very very well.
Typical Usage #2
To show related links at the side column. copy this code into a new HTML/Javascript widget and place at the side in the page elements section.
Again, If you already included jQuery into your blog. no need to do it again.
Style Widget with CSS
You wouldn't need any CSS unless you need extra customization.
Check Project page for more information.. to follow project changes or request features or submit bugs.
Every variable is optional. exclude it to have default value.
| Option | Description | Default value |
|---|---|---|
| blogURL | Other Blog URL or leave empty to aggregate yours | '' |
| maxTags | max tags to look for on the page | 5 |
| maxPostsPerTag | max posts to be aggregated per tag | 5 |
| maxPosts | Specify a max. to remove extra posts that are least relevant or set to 0 to keep them. | 5 |
| containerSelector | jQuery Selector to find a container to append widget at the end of it, Use 'div.post-body' to have widget appended at the end of your post body. or leave empty so widget is placed where you called it | '' |
| tags | don't specify any and tags are read from page content. or specify a fixed list to aggregate like ['jQuery','JSON']. also setting it to empty array [] will make it work as recent widget all the time. | null means not fixed |
| loadingText | Text to be displayed until widget is loaded. for example 'loading..' | '' means no loading text |
| loadingClass | CSS class will be set on list until widget is loaded which you can use to style the list with an AJAX icon on the background[ajaxload.info]. for example 'related-posts-loading' | '' means no CSS class |
| relatedTitle | H2 Title to be used for related posts widget. To disable title output set this to empty. | 'Related Posts' |
| recentTitle | H2 Title to be used for recent posts widget when there are no tags on the page. Set this to empty and widget is canceled. | 'Recent Posts' |
| postScoreClass | A CSS class prefix to be used to style posts based on relevancy. If you set to 'related-link' and maxTags=5 then related links can have classes like ('related-link1' to 'related-link5') | '' so feature is disabled |
| onLoad | true would insert widget on window load and after all page content(like images) is loaded. or false and widget is loaded after document is ready(before images) | false |
| relevantTip | For demo purpose you can show each post relevancy as a tool tip. set to '\d relevant tags!' and '\d' is replaced with number of tags in common. | '' |
If you want to understand code behind this widget, check [Code behind : A Smarter Related Posts widget for Blogger].
Typical Usage #1
To display related links at the end of every post. copy this code into a new HTML/Javascript widget and place at the bottom of the post or at the footer in the page elements section.
Widget uses jQuery v1.3.2, If you already included jQuery into your blog. no need to do it again.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="http://blogger-related-posts.googlecode.com/files/related-posts-widget-1.0.js" type="text/javascript"></script>
<script type="text/javascript">
relatedPostsWidget({
'containerSelector':'div.post-body'
,'loadingText':'loading...'
});</script>[containerSelector : 'div.post-body'] is the default container selector of your post body as output by blogger. which means find 'div' tag with class="post-body" if you unlikely modified it; find your new selector.
* Note that:
-
- You may also try Fileden as it is only file hosting I know that would give you a direct-link (A Must for javascript to work)
But keep the jQuery URL as is, since Google hosts jQuery(and others) very very well.
Typical Usage #2
To show related links at the side column. copy this code into a new HTML/Javascript widget and place at the side in the page elements section.
Again, If you already included jQuery into your blog. no need to do it again.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="http://blogger-related-posts.googlecode.com/files/related-posts-widget-1.0.js" type="text/javascript"></script>
<script type="text/javascript">
relatedPostsWidget({
'loadingText':'loading...'
});</script>Style Widget with CSS
You wouldn't need any CSS unless you need extra customization.
<style type="text/css">
/* Widget Div */
#related-posts{
/* Add your styles */
}
/* Widget H2 heading */
#related-posts h2{
/* Add your styles */
}
/* Widget UL list */
#related-posts ul{
/* Add your styles */
}
/* Widget loading text */
#related-posts-loadingtext{
color:green;
}
/* Widget loading class set on UL until it is loaded */
/* you will need set the option: 'loadingClass':'related-posts-loading' */
.related-posts-loading {
/* Ajax Icon as background */
background:transparent url(Load.gif) no-repeat right top;
}
/* Style links based on relevacny */
/* you will need set the option: 'postScoreClass':'related-post' */
.related-post1{ font-size:90%}
.related-post2{ font-size:90%}
.related-post3{ font-size:100%}
.related-post4{ font-size:110%}
.related-post5{ font-size:120%}
</style>Check Project page for more information.. to follow project changes or request features or submit bugs.




Its nice to hear this one. This is what im looking for..I've searched a lot and i found this. But it does not show any related post in my blog...Can you help me?Heres my blog
www.gigsilonggo.co.cc
@Junnjun Mendoza,
I don't see the widget code been setup on your blog. for further help email me.
I need a jquery that automatically display search results of keyword from google. Can this widget do that?
@Search Engine Optimization Service,
It can get related posts from another blogger blog.. based on current posts tags or a fixed tag list.
or you can check Google AJAX Search API for Google search results
Hey mike,
This is really nice. I want to implement it for both Recent posts and Related posts but at both the place it's showing Related posts. Please guide me. I am @ http://techieteasy.blogspot.com/
I will appreciate your help. Thank you.
@techieteasy
To get related posts, the widget extracts tags from tags links in your page. your blog doesn't use any tags..!
If you need further help.. email me.
Also please don't include the widget js from widget download link.. you should host the js file on your own.
please check my blog, it doesn't work for me http://kyyeutandan.blogspot.com
it's on the top right, with label "Test"
@mnkt,
I don't see the widget js file included on your site..
oops, Execuse me for the wrong comma in sample code. I fixed the code.. Commas should be placed after the first element in options array when calling relatedPostsWidget()
i changed it to txt file and place in googlesite, is it ok?
I sent you mail, it will be more convenient
I love this...! I am soon going to blog on this giving you the credits! I will just give a detail code on CSS :) also there is a way to host the file directly by blogger! Just convert it to escaped character and then place inside a script tag before the closing head! Now blogger itself will host the file ;)
btw please fix the height of the iframe of your comment area! I have to edit it live with Firbug to put this comment :|
Thanks @Swashata for your feedback..
You mean inserting script file content inside the head of the blog instead of including it by its URL?
I don't see the iframe problem on my Firefox, what version do u have?
Exactly! Have a look at this!!! Inserting jQuery file directly on blogger.... Also check the source code of my blog! I have just converted the whole code into escaped character! Like converted > to > and then inserted the whole code to the head of the blog! Blogger XML parser converts them to normal character while making the html file! :)
Also I am using Firefox 3.5.1! And I am still having the iframe issue! I cant put the captcha! On the next comment I am giving you a screenshot! (If I face similar problem in this comment)
Ok! Here are two images
1. Without making modification with Firebug: http://i27.tinypic.com/24v8wuc.jpg
2. After modifying with Firebug: http://i26.tinypic.com/1zcfoub.jpg
@Swashata,
Inserting all Javascript/CSS code in the head will slow down all your pages downloading. on the other hand including a Javascript/CSS files would get cached by the browser after the first request on your site which will down-size your pages and speed up loading...
Thanks alot for the descriptive screen-shots, It should be fixed now...
@Mike
No problem buddy :) The effort you took on making the JS code and writing the tutorial is really much much big than taking a screenshot :)
I was concerned about the cache But, the problem is that I dont have any premium/paid host right now! Also Google page service has stopped for new users!! So if I link to some free host then the loading time will increase heavily! Also I have seen much improvement after attaching the jQuery plugins directly! I dont know about how google hosts jQuery files... Should I remove the jQuery framework and put the link from Google...
You're correct about Google Pages, they're Phasing it out.
Fileden is free file hosting and works fine for me.. and note that JavaScript file is only queued the first time the user visit your site!
Still, to speed up things up, you can Minify/combine many javscripts into one file.
Yes, you should let Google host jQuery for you.. [http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js], it would be much better..
Thanks! I have now removed the scripts from my templates and have used google link instead! It has now reduced my blogger template size from 150kb to 99 kb :)
@Swashata,
Great.. you welcome
You... are awesome.
I've been messing with my blog's html for hours trying to get a related posts widget to work, and all along there this simple version that lets me just add it to the widget page! So much easier... gonna go look at your other widgets, too.
@Ocean,
Thanks for your feedback..
Briliant thats all i can say
@charly,
Thanks.. I'm glad to see the widget running on your blog..
I love it... best thing i like about it is that it is really simple to install as a widget instead of hacking into template code.
One feature suggestion: Can you change the hardcoded h2 tag to h4. Reason as that blogger templates usually use h1-h3 for blog title, date and post title so starting from h4 should be nice.
@Salman,
H2 is usualy used for widget title. that's why!
If you need to style it your way: use
#related-posts h2{}
Right. I am displaying the widget below my blog item instead of sidebar. I therefore tweaked the css to make it look like h4 and it blends nicely with the content :)
Finally got a better web host! And that is Google Code itself! Now I am hosting my compressed JS file and CSS file from google code only! It is far better then fileden! I am using SubVersion system and got the tut from here ==> http://engtech.wordpress.com/2007/03/03/howto_google_code_hosting_subversion_tortoisesvn/
Also it gives 1GB of bandwidth per day which is more than enough for me at this moment !
@Swashata,
Doesn't look legitimate! I wouldn't advice anybody to do that..!
Trying to get this to work..but all i am getting is Recent post then loading...so curious if anyone has any ideas...url...http://www.forecastfirst.com/special/aim
@Takhomasak,
I don't see the widget JavaScript code being setup on your page.
This widget needs to find tags/labels on your page to work as related posts widget. otherwise it works as recent posts widget.
for further help contact me.
Mike - nice code! Have you noticed it interfering with the addthis.com js files?
You can see the error here: http://www.onpreinit.com/2009/10/blogger-seo-limitations-url-length.html.
Nevermind - looks like it's going to be fixed in their next release:
http://www.addthis.com/forum/viewtopic.php?f=5&t=20717&st=0&sk=t&sd=a&sid=8da4380a45a6dc43adc95397f4c25dc2&start=10.
@Nariman,
No problem.. in the meanwhile you might wanna try sharethis.com
Awesome, worked like a champ. Saves a lot of work on my end!
@Kris,
Thanks for your feedback :)
Uberawesome Mike ! :) this one is def gonna get you lots o' love from the Blogger platform community - told ya u were UberKewl ! :))
M.
@Mia,
thanks for your feedback and the RT's.
You have an Uberawesome blog!
Thanks for this one. I will try it out soon.
hi, i was trying it out on my blog. Please check that here:
my blog, on right column, but its showing recent posts by default. How can i change it to show related posts? I did what you exactly showed on this article, Please help me.
@Rana,
You have no tags on post page! that's why :)
hello
when i try to put arabic text in the array tag ['إسلام','علم']
its not work, but when i put english text the script work fine ! so please anyone have an idea how to fix the arabic character problem in case my blog tags in arabic char.
Hi, Thanks for your code! I have implemented it in my blog http://annoyances-resolved.blogspot.com and it works superb. I would like to reduce the size of the text "Related Posts" to match the rest of the blog. I gather you would want to use style.css. Where do you put this style.css in blogger and which field do you need to modify to reduce the font size for the text "Related Posts" ?
@Anonymous with arabic Issue,
Can you email me with more details?
@Mentor,
You need to set style of #related-posts h2{} and place that in your template code [Layout > Edit HTML] inside of <b:skin><![CDATA[ and ]]></b:skin>
I read your blog very impressed seen this kind of important information’s. Really am interested to back to your blog again to gather some more information’s i will copy that to my site if you do not mind you are the best
@aram,
Sure, as long you play by the rules of the License :)
thanks for sharing..
Thank you Mike! You have made the code idiot proof. I have used it on my blog and it works very well!
How can i change those white dots to something else?Like a 16x16 RSS icon? :]
@Gothika_47,
Related posts links are displayed as unordered list.. check this quick tutorial on how to style it using simple CSS code.