How to Random Post for Blogger / Blogspot blogs?


This also a cool  gadget.You can keep this widget without any hassle.Random Post for blogger is also a important  feature like Related posts.Keep your readers live withing your site.
Log in blogger Click Design

Page Elements  


Add Gadget
 
HTML/JavaScript
Copy following Java script code and paste(Give the title Randomn post or what ever you like)

<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 = 'View Random Post'; document.getElementById('myLuckyPost').appendChild(a); } </script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script>

Once you have installed the widget, you can change the link text. The default value is "View Random Post". To change this, view the code and search for View Random Post, and change it to any desired text.

0 comments: