In WordPress you can show number of posts written by an author, you can do this even in Blogger, but you need Java script to do that.
Showing author name and number of post he/she has written on the blog is useful for multi author blogs. As multi author blogs proudly display their number of authors and post count to the public.
The Java script code we are using here can also be used on single author blogs.
Installation is pretty simple, add the HTML/Javascript gadget to your blog and paste the code there.
<style type="text/css">
.author-line {margin: 3px 0;}
.author-avatar {vertical-align:middle;}
</style>
<script type="text/javascript">
//
// Blog authors gadget, works like multi author profile gadget,
// but with post counts and avatars, ordered most written first,
// by MS-potilas 2012. See http://yabtb.blogspot.fi/2012/06/profile-gadget-with-avatars-and-post.html
//
// CONFIG:
var maxUserNameLength = 42; // 0: don't cut, >4: cut usernames
//
var txtAuthorLine = '[image] [user] has written [count] [post]'; // can also use [#] (=position)
//
var sizeAvatar = 20;
var cropAvatar = true;
//
var urlNoAvatar = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCucHP3U16XqwgLGDa9Ui9YvzUrxegjyL13xpw-TC_WDIN2Tfd-ugTQ-GVvpmG0sI7LexIdLofZpghthOGSmpaYF2KL4JdMF7LySYb-tv9DEIas7MpkRltGtWjl0giGX-aiddABrGlUJ4/"+sizeAvatar+"/avatar_blue_m_96.png"; // http://www.blogger.com/img/avatar_blue_m_96.png resizeable
// config end
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;
if(author.gd$image && author.gd$image.src)
avaimg = author.gd$image.src;
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);
if(item.count != 1)
text = text.replace('[post]', "posts");
else
text = text.replace('[post]', "post");
return text;
}
var blauthors = {};
var blndxbase = 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;
if(blauthors[authorName])
blauthors[authorName].count++;
else {
var aut = new Object();
aut.author = entry.author[0];
aut.count = 1;
blauthors[authorName] = aut;
}
}
if(json.feed.entry.length == 500) {
blndxbase += 500;
document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&start-index='+blndxbase+'&alt=json-in-script&callback=showAuthors"></'+'script>');
return;
}
var tuplear = [];
for(var key in blauthors) tuplear.push([key, blauthors[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;
});
// output authors:
document.write('<di'+'v class="blog-author">');
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('</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>
No comments:
Post a Comment
All comments are moderated. Keyword names are deleted.