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 Out New Edition
of this widget that is loaded with pretty new features like posts thumbnails and transition effects..
of this widget that is loaded with pretty new features like posts thumbnails and transition effects..
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.
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>
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 :)
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.
Thanks for the widget, Mike, it's very easy to use and to configure!
I've been looking for something like this!
I have added it to my blog already.
@gxg,
you welcome and thanks for your feedback :)
I have installed it on my blog.It's working!Thanks!
Hi, Mike! I noticed a small issue with the widget.
If you tag the URL with Google Analytics parameters like this:
http://exde601e.blogspot.com/2010/04/chromes-silent-update-extending-to.html?utm_source=FeedBurner+feed&utm_campaign=Feed:+Fors
the widget considers this a entirely different page / blog post and when it generates the list of related posts, it puts the same one (without the tags) at the top (which is normal, since they have exactly the same tags).
Could you change the script so that it discards the tags or everything else after the '?' in the URL, so that it doesn't put the same article on the related list? Thanks!
Hi Mike,
Thanks for this Smart widget !
i did translate your tutorial to Arabic Blogger Community (+adding some points)
http://www.italib.net/2010/04/related-posts-widget.html
Keep it Up!
please visit my blog and tell me unnecessary categories for my site or blog
thank you so much for this wonderful widget I was looking for it for a long time.
Now I got a little question I followed your instructions to install the code in to the footer in the page elements section , it appears fine under the posts as required but it also appears in the pages , what should I do to make stop from appearing the pages !!??
hey Mike , I forgot to say that I am using the new template designer
Zeinobia, you are most welcome :)
It works on pages as a recent posts widget -as there are no tags to aggregate related posts for. So, to disable that behavior, set the "recentTitle" option to an empty string ''.
Thanks Mike , it worked as a charm :)
Sorry Mike but I noticed something that the recent posts not the related posts are shown , how can I fix this !!??
@Zeinobia,
No problem, Can you give me an example link?
thanks Mike
now this is an example link which caught my attention to the problem
http://egyptianchronicles.blogspot.com/2009/08/struggle-on-nile-background.html
as you can see this is an old post from last year and yet I found the recent posts in the related section
@Zeinobia,
That behavior is alright.. The widget will get latest posts of related tags, so it might look like they are recent posts but they are not!
As you can see the related posts are NOT sorted descending(Newer first) as it would be in case of recent posts.
thanks for the script.. installed it on my blog.. it wud be easier if you also explain the parameters that can be passed in it...
@frontierville,
you welcome :)
Check Widget Options
* Check Out New Edition
of this widget that is loaded with pretty new features like posts thumbnails and transition effects..
Thank uuu for sharing:-)
Excellent template design...
Looking very elegant I must say...