6 Random Posts Widget Blogger

Seen a lot people finding a Random Post widget for there blog? Then thought should have an tutorial on how to install it too in the blog.Well, here it is. If you want to know what it do is, whenever a reader click on link created by this widget all the times a different post will open for the reader in the blog as by luck.

Now lets see how to install it in your blog as it is very simple.

Go to Page Elements and click on Add a Gadget on the sidebar. Select HTML/Javascript and add the javascript code given below and save the widget/gadget.


<div id="myLuckyPost"></div> <script type="text/javascript"> function showLucky(root){ var feed = root.feed; var entries = feed.entry || []; var entry = feed.entry[0]; for (var j = 0; j < entry.link.length; ++j){if (entry.link[j].rel == 'alternate'){window.location = entry.link[j].href;}}} function fetchLuck(luck){ script = document.createElement('script'); script.src = '/feeds/posts/summary?start-index='+luck+'&max-results=1&alt=json-in-script&callback=showLucky'; script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); } function feelingLucky(root){ var feed = root.feed; var total = parseInt(feed.openSearch$totalResults.$t,10); var luckyNumber = Math.floor(Math.random()*total);luckyNumber++; a = document.createElement('a'); a.href = '#random'; a.rel = luckyNumber; a.onclick = function(){fetchLuck(this.rel);}; a.innerHTML = 'Are ya feeling lucky, punk?'; document.getElementById('myLuckyPost').appendChild(a); } </script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script><noscript><a href="http://anshuldudeja.blogspot.com" target="_blank">Blogger Hacks</a></noscript>


I hope you will install it very easily Good Luck!!

If you liked This Just Subscribe With US to Get Recent Widgets, Hacks And Templates To your Inbox.
Share/Bookmark

6

lvs said...

I like the changes you keep making to your blog. And again a very useful tip from you.

January 30, 2009 8:32 PM
Anonymous said...

;)) nice blog , keep it up ;)

April 12, 2009 3:26 AM
wazzupweb said...

wow it works!! this is so amazing!! you're so great!!!!! almost all the hacks i needed is here!! this blog is worth FOLLOWING!

May 21, 2009 8:03 AM
wazzupweb said...

it doesn't work for me..

May 21, 2009 8:11 AM
The Blind Assassin said...

i like this!

October 26, 2009 2:35 AM
Nathawud said...

Thk it work!!
http://hackublog.blogspot.com

November 26, 2009 11:49 PM