Blog Tutorial for Newbie
Blogger Tutorial | Wordpress Tutorial | Free Blogger Template | Free Wordpress Template

How to install a Random Post

For the new bloggers who want to make more visitors more in our blog, install Random Post for more options which are presented.

First :

login to Dashboard -> open Template -> Edit HTML -> dont forget to backup the template first :)

Then copy the code below and paste right over the tag </head>


<script type="text/javascript">
//<![CDATA[
var _yourBlogUrl = "http://editing-blog.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 > 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;
}
//]]>
</script>


Do not forget to change the color red with your blog URL, then do not forget saved.

Second :

Then add a page Element -> HTML / Javascript

<a href="javascript:randomPost();">View Random Post</a>

Do not forget to save and see the results :)

source : http://www.o-om.com/2007/12/cara-pasang-random-post-menampilkan.html
0 comments:
CO.CC:Free Domain Free Web Hosting with Website Builder
Earn money from your website/blog by, selling text links, banner ads - Advertisers can, buy links, from your blog for SEO. Get paid through PayPal PJN July Promo

Your Foot Print


ShoutMix chat widget

Recent Posts

Labels

Contributors