How to Display a Random Post in your Blog?

When a User Clicks on an Image, It will load a Random Post.
Just add the following Script in your Blog.



<div id="myLuckyPost"></div> <script type="text/javascript"> function
showLucky(root){ var feed = root.feed; var entries = feed.entry || []; var entry
= feed.entry[0]; window.location = entry.link[0].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 = '<img src="http://1.bp.blogspot.com/_aOVUVB-gmBA/SLVrcI5Zw6I/AAAAAAAAAmo/oi5iK_m_lxQ/s320/dice.PNG">';
document.getElementById('myLuckyPost').appendChild(a); } </script> <script src="/feeds/posts/summary?max-results=0&amp;alt=json-in-script&amp;callback=feelingLucky"></script>



Just change the Image URL for different Image other than Dice.

No comments: