Advertisement
mspotilas

Author box for blogger

Jun 5th, 2012
2,253
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. var aut_desc = {};
  8. var auth_url = {};
  9.  
  10. // CONFIGURATION
  11.  
  12. var multiAuthor = true;        // for multi author blogs set this to true
  13. var onePost = "post";
  14. var manyPosts = "posts";
  15.  
  16. // you _should_ give description for each author, can use html with formatting, contact links, etc.:
  17.  
  18. aut_desc['MS-potilas'] = '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>.';
  19.  
  20. aut_desc['some other'] = 'Description of this other person.';
  21.  
  22.  
  23. // you _can_ override author links, but it is not necessary:
  24.  
  25. auth_url['MS-potilas'] = 'http://www.blogger.com/profile/05137522196636058302';
  26.  
  27. auth_url['some other'] = 'http://www.somelink.com/';
  28.  
  29.  
  30. // Configure CSS:
  31. //]]>
  32. </script>
  33. <style type='text/css'>
  34. .post-author-block {
  35.   display: none;
  36.   margin: 20px 0 0;
  37.   padding: 5px 10px;
  38.   background-color: #f0f0f0;
  39.   border: 1px solid #e0e0e0;
  40.   line-height: 1.6;
  41.   font-size: 90%;
  42. }
  43. .authorinfoname { font-weight: bold; }
  44. .authorinfoimage { float: left; margin-right: 8px; width:48px;}
  45. </style>
  46. <!-- Customize this div, which contains the author box: -->
  47. <div class='post-author-block'>
  48.   <h2>This post was written by</h2>
  49.   <a class='authorinfolink'><img border='0' class='authorinfoimage' src=''/></a>
  50.   <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>
  51.   <div><span class='authorinfodescription'></span></div>
  52.   <div style='clear:both;'/>
  53. </div>
  54. <script type='text/javascript'>
  55. //<![CDATA[
  56. var authors = {};
  57. var ndxbase = 1;
  58. var auname = "";
  59. function getAuthorInfo(json) {
  60.   var authorName = "";
  61.   for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
  62.     var entry = json.feed.entry[i];
  63.     authorName = entry.author[0].name.$t;
  64.     if(authors[authorName])
  65.       authors[authorName].count++;
  66.     else {
  67.       var aut = new Object();
  68.       aut.author = entry.author[0];
  69.       aut.count = 1;
  70.       authors[authorName] = aut;
  71.     }
  72.     if(!multiAuthor) break;
  73.   }
  74.   if(multiAuthor && json.feed.entry.length == 500) {
  75.     ndxbase += 500;
  76.     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>');
  77.     return;
  78.   }
  79.   if(!multiAuthor)
  80.     authors[authorName].count = json.feed.openSearch$totalResults.$t;
  81.   au = auname;
  82.   if(authors[au]) {
  83.     if(aut_desc[au] && aut_desc[au] != "")
  84.       $(".authorinfodescription").html(aut_desc[au]);
  85.     $(".authorinfopostpost").text(parseInt(authors[au].count) == 1 ? onePost : manyPosts);
  86.     $(".authorinfopostcount").text(authors[au].count);
  87.     if(authors[au].author.gd$image)
  88.       $(".authorinfoimage").attr("src", authors[au].author.gd$image.src);
  89.     $(".authorinfoimage").attr("title", au);
  90.     $(".authorinfolink").attr("title", au);
  91.     $(".authorinfoname").text(au);
  92.     if(authors[au].author.uri && authors[au].author.uri.$t != "")
  93.       $(".authorinfolink").attr("href", authors[au].author.uri.$t);
  94.     if(auth_url[au] && auth_url[au] != "")
  95.       $(".authorinfolink").attr("href", auth_url[au]);
  96.     $(".post-author-block").show();
  97.   }
  98. }
  99. //]]>
  100. auname = &quot;<data:post.author/>&quot;;
  101. //<![CDATA[
  102. 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>');
  103. //]]>
  104. </script>
  105. </b:if>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement