[iklan]

Random Post javascript


Untuk catatan dari cara membuat random post di blogspot dengan menggunakan javascrip. Mungkin suata saat diperlukan untuk dipasang di tempat lain. Diblog yang baru atau teman-teman juga bisa copas. Dibawah ditampilkan kode scriptnya, agar mudah dicopas. Random Post javascript



Berikut ini adalah code-codenya. Yang mau pasang random post di blog atau di halaman, atau di widget blogger, bisa tinggal copas.

<style>
#rp img{
border-radius:10px;
float:left;
margin-right: 5px;
height:75px;
transition:all 0.2s linear 0s}
#rp img:hover{transform:scale(1.1)}
ul#rp{
list-style-type:none}
#rp a{
font-size:12px;
padding:0px auto 5px}
#rp a:hover{text-decoration:none}
.rs{
font-size:11px;
padding:5px;
margin-right:8px}
#rp li{
margin-bottom:10px;
border-bottom:1px solid #EEE}
</style>
<ul id="rp">
<script type="text/javaScript">
var num = 6;
var cha = 230;
var det = 'no';
var comm = 'Comments';
var commd = 'Comments Disabled';
var cur = [];
var tot = 0;
var cur = new Array(num);
function ranp(json) {
    tot = json.feed.openSearch$totalResults.$t
}
document.write('<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&max-results=0&callback=ranp\"><\/script>');
function getv() {
    for (var i = 0; i < num; i++) {
        var found = false;
        var rndValue = get_r();
        for (var j = 0; j < cur.length; j++) {
            if (cur[j] == rndValue) {
                found = true;
                break
            }
        };
        if (found) {
            i--
        } else {
            cur[i] = rndValue
        }
    }
};
function get_r() {
    var ranNum = 1 + Math.round(Math.random() * (tot - 1));
    return ranNum
};
</script>
<script type="text/javaScript">
function ran_p(json) {
    for (var i = 0; i < num; i++) {
        var entry = json.feed.entry[i];
        var ranptitle = entry.title.$t;
        if ('content' in entry) {
            var ranpnippet = entry.content.$t
        } else {
            if ('summary' in entry) {
                var ranpnippet = entry.summary.$t
            } else {
                var ranpnippet = "";
            }
        };
        ranpnippet = ranpnippet.replace(/<[^>]*>/g, "");
        if (ranpnippet.length < cha) {
            var ranp_snippet = ranpnippet
        } else {
            ranpnippet = ranpnippet.substring(0, cha);
            var whitespace = ranpnippet.lastIndexOf(" ");
            ranp_snippet = ranpnippet.substring(0, whitespace) + "&#133;";
        };
        for (var j = 0; j < entry.link.length; j++) {
            if ('thr$total' in entry) {
                var commnum = entry.thr$total.$t + ' ' + comm
            } else {
                commnum = commd
            }; if (entry.link[j].rel == 'alternate') {
                var ranpurl = entry.link[j].href;
                var ranp_date = entry.published.$t;
                if ('media$thumbnail' in entry) {
                    var ranpthumb = entry.media$thumbnail.url
                } else {
                    ranpthumb = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv10Y-zSFHZBzUd0Y_GCDqr_v9ualhbQ9cKfq9G8_Ju9BFkf5OjF9xeRPZwForbnW41sEm7ROBelvBjS11pI-4IdMD0L-ngbaR42xr8ihxybLM06X4HziivD_5rwsmRbKuHF-e7STcR2U/s72-c/4+pencarian+cari+search+icon+call+%252823%2529.png"
                }
            }
        };
        document.write('<li>');
        document.write('<a target="_blank" href="' + ranpurl + '" rel="nofollow"><img alt="' + ranptitle + '" src="' + ranpthumb + '"/></a>');
        document.write('<div><a target="_blank" href="' + ranpurl + '" rel="nofollow">' + ranptitle + '</a></div>');
        if (det == 'yes') {
            document.write('<span><div  class="random-info">' + ranp_date.substring(8, 10) + '.' + ranp_date.substring(5, 7) + '.' + ranp_date.substring(0, 4) + ' - ' + commnum) + '</div></span>'
        };
        document.write('<div class="rs">' + ranp_snippet + '</div><div style="clear:both"></div></li>')
    }
};
getv();
for (var i = 0; i < num; i++) {
    document.write('<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&start-index=' + cur[i] + '&max-results=1&callback=ran_p\"><\/script>')
};
</script>
</ul>



0 comments:

Posting Komentar

Catatan Sementara

 
© - Catatan Afandi Kusuma | Buku.suwur | Furniture.Omasae | JayaSteel | OmaSae | Alat Pesta + Wedding | Galvalum | DepoAirIsiUlang | Seluruh Arsip