Random Post in Blogger
How to make random post in blogger/blogspot?
This article guide you to make a random post. By using this the visitor will browse your page
For classic template on blogspot , or in a layout template if you want
more control over where the link is inserted you can use the following.
Paste the below script code in the <head> of the template
//<![CDATA[
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 readLucky(root){
var feed = root.feed;
var total = parseInt(feed.openSearch$totalResults.$t,10);
var luckyNumber = Math.floor(Math.random()*total);
luckyNumber++;
fetchLuck(luckyNumber);
}
function feelingLucky(){
var script = document.createElement(’script’);
script.type = ‘text/javascript’;
script.src = ‘/feeds/posts/summary?max-results=0&alt=json-in-script&callback=readLucky’;
document.getElementsByTagName(’head’)[0].appendChild(script);
}
//]]>
</script>
Then put the following link wherever you want
You can change around the anchor text to suit.
FTP blogs, can still use it, but need the following modified script instead of the above
//<![CDATA[
var luckyBase = ‘http://www.blogger.com/feeds/YOURBLOGID/posts/summary’;
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 = luckyBase +
‘?start-index=’+luck+’&max-results=1&alt=json-in-script&callback=showLucky’;
script.type = ‘text/javascript’;
document.getElementsByTagName(’head’)[0].appendChild(script);
}
function readLucky(root){
var feed = root.feed;
var total = parseInt(feed.openSearch$totalResults.$t,10);
var luckyNumber = Math.floor(Math.random()*total);
luckyNumber++;
fetchLuck(luckyNumber);
}
function feelingLucky(){
var script = document.createElement(’script’);
script.type = ‘text/javascript’;
script.src = luckyBase + ‘?max-results=0&alt=json-in-script&callback=readLucky’;
document.getElementsByTagName(’head’)[0].appendChild(script);
}
//]]>
</script>
The line
var luckyBase =
‘http://www.blogger.com/feeds/YOURBLOGID/posts/summary’;
MUST be modified to use your blogs unique id number. You can
either get this from your dashboard links (links will all have
blogID=”XXXXXX”, with the XXXX’s being your ID) or it can be viewed on
the source of your published page in the meta information. Use the same link as above to activate the random post.
You can use this script into blogger classic or new templates.
Hope this will useful for us. Regards.
Source THIS SITE



Comments (No comments)
What do you think?