Random post adalah suatu cara menampilkan posting secara acak, Sebenarnya cara memasang random post sudah lama ada dan sudah banyak yang menulis, namun blogger yang baru memulai membuat blog masih saja bingung, mungkin tutorila yang digunakan/ditemukan masih menggunakan bahasa inggris. Agar gak membuat sahabat blogger kecewa saya tulis aja artikelnya secara singkat.
Langkah mudah membuat Random Post:
Pertama:
Buka Template -> Edit HTML -> Jangan lupa lakukan backup template :)
Kemudian Copy-paste kode dibawah ini biasanya atas tag </head>
<script type="text/javascript">
//<![CDATA[
var _yourBlogUrl = "http://tutorial-on.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>
=> Jangan lupa ganti warna merah diatas dengan nama blog kita, jika sudah jangan lupa disimpan
Kedua:
Kemudian Tambahkan sebuah Element halaman -> HTML/Javascript
<a href="javascript:randomPost();">View Random Post</a>
Jangan lupa disimpan dan lihat hasilnya :)
5 komentar:
Very good article post.Thanks Again. Awesome
This is an extremely superb web page you could have clicking here. The challenge can be quite informative and also straight to the point. Ecstatic to read simple things another recommendation of your site the next time.
It’s so lucky for me to find your blog! So shocking and great! Just one suggestion: It will be better and easier to follow if your blog can offer rrs subscription service….
As far as me being a member here, I wasn’t aware that I was a member for any days, actually. When the article was published I received a username and password, so that I could participate in Comments, That would explain me stumbuling upon this post. But we’re certainly all members in the world of ideas.
following are some references to online sites I always connect to seeing that we feel these are seriously worth visiting
Post a Comment