Untuk membuatnya cukup mudah, tinggal ikuti tutorial berikut . . . .
Langkah Pertama :
1. Masuk ke blogger
2. Buka Layout => Edit HTML
3. Backup dulu template Sobat ( Download Template Full )
4. Centang Expand Widget template
5. Masukkan kode di bawah ini , di atas kode </head>
(Cara nyari kode </Head> pakai shortcut CTRL+F)
<script type="text/javascript">
//<![CDATA[
var _yourBlogUrl = "http://with-miqdi.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>
//<![CDATA[
var _yourBlogUrl = "http://with-miqdi.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>
Note : Ganti yang warna merah dengan alamat blog Sobat
Langkah Selanjutnya :
1. Masuk ke blogger
2. Buka Layout => Page Element =>Add a Gadget => Html Javascript
3. Masukkan kode berikut,
3. Masukkan kode berikut,
<a href="javascript:randomPost();">View Random Post</a>
Note : Yang merah, ganti dengan judul " Random post" Sobat
Selamat Mencoba
Sumber : prasutan.blogspot.com
0 komentar:
Posting Komentar