Credits

Random Posts Widget for Blogger


Did you ever desired to add a widget with a link to show a random blog post of your blogger/blogspot blog? Here is a way to add some ex  Black Blogger3  Blogger Manu    citement in your blog by adding a Random Post link. Whenever any user will click on that Random Link, your user will be navigated to a random post of your blog.

How to Show Random Posts in Blogger ?

  • Login to Your Blogger Account
  • On Your Dashboard, Click on Design (see below shown picture for further assistance)
  • Now Click on Add a Gadget, Use HTML/Javascript Gadget and Place Below Given Code
<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 = ‘View Random Post’; document.getElementById(‘myLuckyPost’).appendChild(a); } </script> <script src=”/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky”></script>
  • Save and Its Done !
Above Given Javascript will show a random post link with text View Random Post , If you want to show some other text, just modify the bold text shown in Javascript.

No comments :

 

Website | The content is copyrighted and may not be reproduced on other websites. © | All Rights Reserved 2014

FreshDream Blogger template by Tacni