Script Untuk Jumlah Postingan Author (blogspot)

Discussion in 'Blogger' started by KangAndre, Feb 21, 2016.

  1. KangAndre

    KangAndre Member

    Joined:
    Jan 25, 2014
    Messages:
    9,924
    Likes Received:
    2,605
    Trophy Points:
    313
    Terkadang ada blog yang dikelola oleh beberapa orang sebagai penulis artikel (kontributor). Script di bawah ini untuk mengetahui berapa jumlah artikel yang telah dibuat oleh masing-masing kontributor dan jawaban atas thread https://www.bersosial.com/threads/ask-menampilkan-jumlah-posting-kontributor.31732/

    Script ini digunakan di widget <HTML/JavaScript> yang dapat diletakkan di sidebar atau footer. Bisa juga di buat untuk page (gunakan mode html).

    Silahkan kembangkan sendiri untuk CSS-nya menyesuaikan template yang ada.
    DEMO: http://kanalarudam.blogspot.co.id/ sidebar paling bawah.

    Code:
    <style type="text/css">
    .author-line     {margin: 3px 0;}
    .author-avatar   {vertical-align:middle;}
    </style>
    <script type="text/javascript">
    // widget blogger.com jumlah postingan author dengan avatar menurut penulis pertama,// 
    var maxUserNameLength = 42; // 0: jika ingin ditampilkan semua//
    var txtAuthorLine = '[image] [user] telah mengirim : [count] posts'; // dapat menggunakan [#] (=position)//
    var sizeAvatar = 20;
    var cropAvatar = true;
    var urlNoAvatar = "http://lh4.googleusercontent.com/-069mnq7DV_g/TvgRrBI_JaI/AAAAAAAAAic/Iot55vywnYw/s"+sizeAvatar+"/avatar_blue_m_96.png"; 
    // http://www.blogger.com/img/avatar_blue_m_96.png // 
    // untuk IEs & IE :
    if(!Array.indexOf) { 
     Array.prototype.indexOf=function(obj) {
      for(var i=0;i<this.length;i++) if(this[i]==obj) return i;
      return -1;
    }}
    function replaceAuthorVars(text, item, position)
    {
      if(!item || !item.author) return text;
      var author = item.author;
    
      var authorUri = "";
      if(author.uri && author.uri.$t != "")
        authorUri = author.uri.$t;
    
      var avaimg = urlNoAvatar;
      var bloggerprofile = "http://www.blogger.com/profile/";
      if(author.gd$image && author.gd$image.src && (authorUri.substr(0,bloggerprofile.length) == bloggerprofile || authorUri == ""))
        avaimg = author.gd$image.src;
      else {
        var parseurl = document.createElement('a');
        if(authorUri != "") {
          parseurl.href = authorUri;
          avaimg = 'http://www.google.com/s2/favicons?domain=' + parseurl.hostname;
        }
      }
      if(avaimg == "http://img2.blogblog.com/img/b16-rounded.gif" && urlNoAvatar != "")
        avaimg = urlNoAvatar;
      var newsize="s"+sizeAvatar;
      avaimg = avaimg.replace(/\/s\d\d+-c\//, "/"+newsize+"-c/");
      if(cropAvatar) newsize+="-c";
      avaimg = avaimg.replace(/\/s\d\d+(-c){0,1}\//, "/"+newsize+"/");
    
      var authorName = author.name.$t;
      var imgcode = '<img class="author-avatar" height="'+sizeAvatar+'" width="'+sizeAvatar+'" title="'+authorName+'" src="'+avaimg+'" />';
      if(authorUri!="") imgcode = '<a href="'+authorUri+'">'+imgcode+'</a>';
    
      if(maxUserNameLength > 3 && authorName.length > maxUserNameLength)
        authorName = authorName.substr(0, maxUserNameLength-3) + "...";
      var authorcode = authorName;
      if(authorUri!="") authorcode = '<a class="profile-name-link" href="'+authorUri+'">'+authorcode+'</a>';
    
      text = text.replace('[user]', authorcode);
      text = text.replace('[image]', imgcode);
      text = text.replace('[#]', position);
      text = text.replace('[count]', item.count);
      return text;
    }
    var authors = {};
    var ndxbase = 1;
    function showAuthors(json) {
      for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
        var entry = json.feed.entry[i];
        var authorUri = "";
        if(entry.author[0].uri && entry.author[0].uri.$t != "")
          authorUri = entry.author[0].uri.$t;
    
        var authorName = entry.author[0].name.$t;
    
        var hash=entry.author[0].name.$t + "-" + authorUri;
        if(authors[hash])
          authors[hash].count++;
        else {
          var aut = new Object();
          aut.author = entry.author[0];
          aut.count = 1;
          authors[hash] = aut;
        }
      }
      if(json.feed.entry.length == 500) {
        ndxbase += 500;
        document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&start-index='+ndxbase+'&alt=json-in-script&callback=showAuthors"></'+'script>');
        return;
      }
      var tuplear = [];
      for(var key in authors) tuplear.push([key, authors[key]]);
    
      tuplear.sort(function(a, b) {
        if(b[1].count-a[1].count)
            return b[1].count-a[1].count;
        return (a[1].author.name.$t.toLowerCase() < b[1].author.name.$t.toLowerCase()) ? -1 : 1;
      });
    
      // hasil authors:
      for(var i = 0; i < tuplear.length ; i++) {
        var item = tuplear[i][1];
        document.write('<di'+'v class="author-line">');
        document.write(replaceAuthorVars(txtAuthorLine, item, i+1));
        document.write('</d'+'iv>');
      }
    }  
    document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&alt=json-in-script&callback=showAuthors"></'+'script>');
    </script>
    
     
    ais elkiram likes this.
  2. arief munandar

    arief munandar Active Member

    Joined:
    May 31, 2015
    Messages:
    710
    Likes Received:
    110
    Trophy Points:
    43
    Mantap mas! Boomark dulu :D
     
  3. Muhammad Khoir

    Muhammad Khoir Super Level

    Joined:
    Jun 10, 2014
    Messages:
    2,850
    Likes Received:
    359
    Trophy Points:
    83
    Google+:
  4. adido

    adido Guest

    Heheheeh thanks bget mas
     
  5. adido

    adido Guest

    Yes, berhasil mas, sekali lg makasih
     
  6. AndroidApkApps

    AndroidApkApps Member

    Joined:
    Dec 11, 2015
    Messages:
    637
    Likes Received:
    40
    Trophy Points:
    28
    Akhirnya di share juga terimakasih sangat bermanfaat :D
     
  7. Qoeple

    Qoeple Member

    Joined:
    Nov 21, 2015
    Messages:
    551
    Likes Received:
    90
    Trophy Points:
    28
    Google+:
    Mantap, saya baru tahu kalo blogspot bisa seperti ini *bagus*
     
  8. KangAndre

    KangAndre Member

    Joined:
    Jan 25, 2014
    Messages:
    9,924
    Likes Received:
    2,605
    Trophy Points:
    313
    Script lama, tapi masih bisa berjalan. Lupa ambil dimana, untung ada di blog ujicoba (2011)
     
    Muhammad Khoir likes this.
  9. KangAndre

    KangAndre Member

    Joined:
    Jan 25, 2014
    Messages:
    9,924
    Likes Received:
    2,605
    Trophy Points:
    313
    Kalau mau image profil sendiri, gunakan profil blogger.com bukan profil google+
    Atau modifikasi agar bisa ngelink ke author arsip.
     
  10. rakiwen

    rakiwen Member

    Joined:
    Feb 11, 2016
    Messages:
    581
    Likes Received:
    47
    Trophy Points:
    28
    Thx banget kang andre... dtggu info2 lainnya kang andre
     
  11. KangAndre

    KangAndre Member

    Joined:
    Jan 25, 2014
    Messages:
    9,924
    Likes Received:
    2,605
    Trophy Points:
    313
    Pada dasarnya semua platform blog bisa karena dasarnya sama = HTML kemudian ada variasi bhs program lainnya seperti php, js, dll. :D
     
  12. Qoeple

    Qoeple Member

    Joined:
    Nov 21, 2015
    Messages:
    551
    Likes Received:
    90
    Trophy Points:
    28
    Google+:
    He.3x ia juga, kalau koding manual iki sing pusing Pak :D
     
  13. Garett

    Garett Super Level

    Joined:
    Apr 13, 2015
    Messages:
    1,084
    Likes Received:
    1,045
    Trophy Points:
    113
    Google+:
    Tidak ada plugin atau server-side scripting pada Blogger, demikianpun Tumblr. Berbeda dengan Wordpress.com dan Wordpress.org, Blogger sepenuhnya penggunakan client-side JavaScript pada Widget dan template. Mereka juga menyediakan JSON API untuk baca data ke client-side.
     
  14. asli3rut

    asli3rut Member

    Joined:
    Sep 6, 2014
    Messages:
    642
    Likes Received:
    44
    Trophy Points:
    28
    Thanks share kodenya kang mas, di bokmark dulu, barangkali nanti akan diperlukan..
     
Loading...

Share This Page