Saturday, December 07, 2013

Membuat widget random post keren dengan tombol share facebook di blogger

membuat random post dengan tombol share facebook Random post merupakan artikel acak yang dipasang di blogger untuk memperkaya konten blog dan menawarkan artikel lainnya pada pengunjung. Untuk membuat widget random post anda tinggal copas dan pastekan di html/javascript. berikut langkah-langkah pemasangannya.
  1. Login ke blogger.
  2. Klik Tata letak, pilih tambahkan gadget.
  3. Pilih Html/javascript.
  4. Copy kode dibawah ini dan pastekan di Html/javascript.
<style>
#hovernyo:hover{background:#f1f1f1;}
.judulnyo { color:#222222;text-decoration:none;}
.judulnyo:hover{text-decoration:none;}
.isinyo {height:65px;max-height:65px;margin: 0px;font-size: 80%;border-bottom:1px solid #cccccc;padding-bottom:8px;padding-right:5px;}
.gambarnyo {margin:3px 10px 3px 0px!important;float: left !important;width:100px;height:60px;!important;}
.rp-pubdate {font-style: italic;margin-bottom: 0px;}
</style>

<script type="text/javascript">
var randarray = new Array();
var l=0;
var flag;
var lengthsummary = 70;
var numofpost=4;
function randomposts(json){
var total = parseInt(json.feed.openSearch$totalResults.$t,10);
for(i=0; i < numofpost;){
flag=0;
randarray.length=numofpost;
l=Math.floor(Math.random()*total);
for(j in randarray){
if(l==randarray[j]){
flag=1;
}
}
if(flag==0&&l!=0){
randarray[i++]=l;
}
}
document.write('<div>');
for(n in randarray){
var p=randarray[n];
var entry=json.feed.entry[p-1];
var item ="";
var posttitle = entry.title.$t || "[Untitled]";
"[Untitled]"
for(k=entry.link.length -1; k >= 0 ; k--){
if(entry.link[k].rel=='alternate'){
item +="<div id='hovernyo'><div style='padding:3px;'><a class='judulnyo' href='" + entry.link[k].href + "'>" + posttitle + "</a></div>";
break;
}
}
var pubdate = new Date(entry.published.$t).toDateString();
item +="";
if('media$thumbnail' in entry)item += "<img class='gambarnyo' src='" + entry.media$thumbnail.url + "' alt='" + posttitle + "' title='" + posttitle + "'>"
var summary = "";
if ("content" in entry) {
summary = entry.content.$t;
}
else if ("summary" in entry) {
summary = entry.summary.$t;
}
var re = /<\S[^>]*>/g;
summary = summary.replace(re, "");
item += "<p class='isinyo'>" + summary.substring(0,lengthsummary) + " ...<a href='https://www.facebook.com/sharer/sharer.php?u=" + entry.link[k].href + "' target='_blank'><br/><img style='float:right;' src='https://lh5.googleusercontent.com/-Wi8QfIkuVbI/UlrbVxYANuI/AAAAAAAABuA/vfXDzh7i3no/w50-h18-no/fbshare.jpg' title='" + posttitle + "'/></a></p></div>";
document.write(item);
}
document.write('</div>');
}
</script>
<script src="/feeds/posts/default?alt=json-in-script&start-index=1&max-results=1000&callback=randomposts" type="text/javascript">
</script>
Note : 
Tulisan warna merah kode CSS, silahkan edit CSSnya sesuai dengan keinginan anda.