2.02.2009

How to Make Random Post

. 2.02.2009

Random Post is a widget that showing  a random post from our blog. It’s will assist visitor to find another post that (maybe) have not read before.

I’ll give you an easy and quick tips for making it:

  1. Choose Edit HTML
  2. Back up your blog first
  3. Then copy-paste this code below, put above </head>

 

&lt;script type="text/javascript"&gt;

//&lt;![CDATA[

var _yourBlogUrl = "http://blogtutormaster.blogspot.com";

function randomPost() {

var script = document.createElement("script");

script.setAttribute("type", "text/javascript");

var theUrl = _yourBlogUrl +"/feeds/posts/summary?alt=json-in-script&callback=getTotalPostsCallback&start-index=1&max-results=1";

script.setAttribute("src", theUrl);

document.documentElement.firstChild.appendChild(script);

};

function getTotalPostsCallback(json) {

var totalResults = json.feed.openSearch$totalResults.$t;

if (totalResults &gt; 0) {

getRandomPostNumber(totalResults);

}

};

function getRandomPostNumber(totalResults) {

var randomNumber = Math.floor((Math.random() * totalResults) + 1);

getRandomUrl(randomNumber);

};

function getRandomUrl(randomNumber) {

var script = document.createElement("script");

script.setAttribute("type", "text/javascript");

var theUrl = _yourBlogUrl +"/feeds/posts/summary?alt=json-in-script&callback=getTheUrlCallback&start-index=" + randomNumber + "&max-results=1";

script.setAttribute("src", theUrl);

document.documentElement.firstChild.appendChild(script);

};

function getTheUrlCallback(json) {

var theUrl = json.feed.entry[0].link[0].href;

window.location.href = theUrl;

}

//]]&gt;

&lt;/script&gt;

 

Change the red code with your blog URL

 

4. Add a gadget, Choose HTML/Javascript Then copy this code:

 

&lt;a href="javascript:randomPost();"&gt;View Random Post&lt;/a&gt;

 

Save and See the Result. Happy Editing

Enter your email To get Update this blog for free:

Delivered by FeedBurner

Related Posts by Categories




Digg Technorati del.icio.us Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy

0 comments:

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Post a Comment

 

BlogRoll

Followers

Master Blog is proudly powered by Blogger.com | Template by o-om.com