Simple Random Posts Widget For Blogger

7/12/2016
Random Posts Widget for Blogger

Random Posts merupakan salah satu fitur yang berguna untuk menampilkan post/artikel secara acak ketika halaman dimuat, baik itu post/artikel terbaru ataupun yang sudah lama.

Dengan adanya widget Random Posts ini, artikel-artikel yang sebelumnya tidak terlihat oleh pengunjung memiliki potensi untuk bisa dilihat.

Singkatnya, Random Posts sangat membantu dalam meningkatkan jumlah page views suatu blog.

Tertarik untuk memasang Widget Random Posts di blog Anda?
Berikut langkah-langkahnya :
1. Buka Blogger
2. Tata Letak/Layout
3. Tambahkan Widget
4. Simpan Kode di bawah ini ke dalam widget :

<style scoped='' type="text/css">
#wiki-random ul{list-style:none;margin:0;padding:0}#wiki-random li{display:block;clear:both;overflow:hidden;list-style:none;border-bottom:1px solid #e3e3e3;word-break:break-word;padding:10px 0;margin:0;}
#wiki-random li:last-child{border-bottom:0;}
#wiki-random li a{color:#444;}#wiki-random li a:hover{color:#444;text-decoration:underline}
</style>
<div id='wiki-random'>Memuat...</div>
<script>
//<![CDATA[
// Random Post Widget
var homePage = 'https://wikiwidgets.blogspot.com',
    maxResults = 10,
    containerId = 'wiki-random';
function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
function shuffleArray(arr) {
    var i = arr.length, j, temp;
    if (i === 0) return false;
    while (--i) {
        j = Math.floor(Math.random() * (i + 1));
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    return arr;
}
function WikiRandomPosts(json) {
    var startIndex = getRandomInt(1, (json.feed.openSearch$totalResults.$t - maxResults));
    // console.log('Get the post feed start from ' + startIndex + ' until ' + (startIndex + maxResults));
    document.write('<scr' + 'ipt src="' + homePage + '/feeds/posts/summary?alt=json-in-script&orderby=updated&start-index=' + startIndex + '&max-results=' + maxResults + '&callback=randomPosts"></scr' + 'ipt>');
}
function randomPosts(json) {
    var link, ct = document.getElementById(containerId),
        entry = shuffleArray(json.feed.entry),
        skeleton = "<ul>";
    for (var i = 0, len = entry.length; i < len; i++) {
        for (var j = 0, jen = entry[i].link.length; j < jen; j++) {
            link = (entry[i].link[j].rel == "alternate") ? entry[i].link[j].href : '#';
        }
        skeleton += '<li><a href="' + link + '">' + entry[i].title.$t + '</a></li>';
    }
    ct.innerHTML = skeleton + '</ul>';
}
document.write('<scr' + 'ipt src="' + homePage + '/feeds/posts/summary?alt=json-in-script&max-results=0&callback=WikiRandomPosts"></scr' + 'ipt>');
//]]>
</script>


Widget Settings


Ganti dan sesuaikan kembali kode yang ditandai berikut ini :

var homePage : Ganti https://wikiwidgets.blogspot.com dengan URL blog Anda.
maxResults : Jumlah judul artikel yang ditampilkan. Misal : 10

5. Simpan dan lihat hasilnya.

Previous
Next Post »

Dapatkan tutorial terbaru dari WikiWidgets?

Subscribe!