Advertisement
mspotilas

Author box for blogger, authors indexed by uri

Dec 27th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <b:if cond='data:blog.pageType == &quot;item&quot;'>
  2.     <script type='text/javascript'>
  3.     //<![CDATA[
  4.     // Author box after post, with post count, for Blogger by MS-potilas 2012.
  5.     // see http://yabtb.blogspot.fi/2012/06/customizable-author-box-with-post-count.html
  6.     //
  7.     // MODIFICATION 12/2014: Authors are indexed by author uri, not author name.
  8.     //                       Can be used if multiple authors have same name.
  9.     //
  10.     var aut_desc = {};
  11.     var auth_url = {};
  12.      
  13.     // CONFIGURATION
  14.      
  15.     var multiAuthor = true;        // for multi author blogs set this to true
  16.     var onePost = "post";
  17.     var manyPosts = "posts";
  18.      
  19.     // you _should_ give description for each author, can use html with formatting, contact links, etc.:
  20.      
  21.     aut_desc['http://www.blogger.com/profile/05137522196636058302'] = 'I am a retired programmer who has multiple sclerosis. In my <a href="http://yabtb.blogspot.com/">YABTB blog</a> I share some of my Blogger hacks I have made.<br>Some links: &nbsp; <a class="authorinfolink">My Blogger Profile</a> &nbsp; - &nbsp; <a href="http://www.youtube.com/user/mspotilas">My YouTube channel</a> &nbsp; - &nbsp; <a href="http://pipes.yahoo.com/mspotilas">My Yahoo! Pipes</a>.';
  22.      
  23.     aut_desc['some_other_author_url'] = 'Description of this other person.';
  24.      
  25.      
  26.     // you _can_ override author links, but it is not necessary:
  27.      
  28.     auth_url['http://www.blogger.com/profile/05137522196636058302'] = 'http://www.blogger.com/profile/05137522196636058302'; // this does nothing, changes the link back to itself :P
  29.      
  30.     auth_url['some_other_author_url'] = 'http://www.somelink.com/';
  31.      
  32.      
  33.     // Configure CSS:
  34.     //]]>ยง
  35.     </script>
  36.     <style type='text/css'>
  37.     .post-author-block {
  38.       display: none;
  39.       margin: 20px 0 0;
  40.       padding: 5px 10px;
  41.       background-color: #f0f0f0;
  42.       border: 1px solid #e0e0e0;
  43.       line-height: 1.6;
  44.       font-size: 90%;
  45.     }
  46.     .authorinfoname { font-weight: bold; }
  47.     .authorinfoimage { float: left; margin-right: 8px; width:48px;}
  48.     </style>
  49.     <!-- Customize this div, which contains the author box: -->
  50.     <div class='post-author-block'>
  51.       <h2>This post was written by</h2>
  52.       <a class='authorinfolink'><img border='0' class='authorinfoimage' src=''/></a>
  53.       <div><a class='authorinfolink'><span class='authorinfoname'/></a> &amp;ndash; who has written <span class='authorinfopostcount'>0</span> great <span class='authorinfopostpost'>posts</span> on <a href="http://yabtb-demo1.blogspot.com/">YABTB demo blog</a>.</div>
  54.       <div><span class='authorinfodescription'></span></div>
  55.       <div style='clear:both;'/>
  56.     </div>
  57.     <script type='text/javascript'>
  58.     //<![CDATA[
  59.     var authors = {};
  60.     var ndxbase = 1;
  61.     var aurl = "";
  62.     function getAuthorInfo(json) {
  63.       var authorUrl = "";
  64.       for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
  65.         var entry = json.feed.entry[i];
  66.         authorUri = entry.author[0].uri.$t;
  67.         if(authors[authorUri])
  68.           authors[authorUri].count++;
  69.         else {
  70.           var aut = new Object();
  71.           aut.author = entry.author[0];
  72.           aut.count = 1;
  73.           authors[authorUri] = aut;
  74.         }
  75.         if(!multiAuthor) break;
  76.       }
  77.       if(multiAuthor && json.feed.entry.length == 500) {
  78.         ndxbase += 500;
  79.         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=getAuthorInfo"></'+'script>');
  80.         return;
  81.       }
  82.       if(!multiAuthor)
  83.         authors[authorUri].count = json.feed.openSearch$totalResults.$t;
  84.       au = aurl;
  85.       if(authors[au]) {
  86.         if(aut_desc[au] && aut_desc[au] != "")
  87.           $(".authorinfodescription").html(aut_desc[au]);
  88.         $(".authorinfopostpost").text(parseInt(authors[au].count) == 1 ? onePost : manyPosts);
  89.         $(".authorinfopostcount").text(authors[au].count);
  90.         if(authors[au].author.gd$image)
  91.           $(".authorinfoimage").attr("src", authors[au].author.gd$image.src);
  92.         $(".authorinfoimage").attr("title", au);
  93.         $(".authorinfolink").attr("title", au);
  94.         $(".authorinfoname").text(authors[au].author.name.$t);        
  95.         if(authors[au].author.uri && authors[au].author.uri.$t != "")
  96.           $(".authorinfolink").attr("href", authors[au].author.uri.$t);
  97.         if(auth_url[au] && auth_url[au] != "")
  98.           $(".authorinfolink").attr("href", auth_url[au]);
  99.         $(".post-author-block").show();
  100.       }
  101.     }
  102.     //]]>
  103.     aurl = &quot;<data:post.authorProfileUrl/>&quot;;
  104.     //<![CDATA[
  105.     document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&alt=json-in-script&callback=getAuthorInfo"></'+'script>');
  106.     //]]>
  107.     </script>
  108.     </b:if>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement