Senin, 01 Juli 2013

How To Add Post Views Counter Plugin in Blogger?


blogger post views counter
I am happy to inform you all that now you can show post views counts below your post title in blogger blog. You have no need of any server or server code to display your post page views. Recently I got aware with a free service calledFireBase. By using this free service you can easily create a dynamic and data-driven plugins for your blogger blog and you have no need of any development skill. Firebase was launched in April 2012. Here you can get 10GB Free bandwidth and 5GB Free storage which is really more than enough for bloggers. In this article you will learn how to add a dynamic page views counter for individual posts in blogger. Before going to the tutorial you may be interested to see a demo!



Note: This plugin will only increment its count value when you visit individual posts but not by just refreshing your blog homepage.

Create FireBase Account


To use this plugin and to store your database of your post views data you must need to sign up for a free account at Firebase.

Once you fill all the details and create your account, then you need to create your first firebase database.

Create a Firebase Database


1. At the bottom right side of your account page, you will get a following create box.


2. Insert your blog name in the text field. In my case I insertedbloggertipstricks.

3. Press create button. Once you press the button your firebase will be create as:

4. Note down your firebase url in any text editor like notepad. We will need it later in our tutorial.

Installing Post views Plugin

  1. Go to your blogger account then choose Template

  2. Backup your template before doing any changes.

  3. Click Edit HTML ---> Proceed ---> Expand Widget Templates.

  4. Press Ctrl+F and find ]]></b:skin>

  5. Just above it, paste the following css code.

/*-------- Post Views  ----------*/
#views-container {
width: 75px;
float: right;
}
.mbtloading {
background: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZNFa70EIYiX8AIN6R6Uy9aPoLZgehFGiXhW_L-dKCej3D6T64VSH-44CrG5AlfxY-q_d8cHxW5RfrY69rYBat-oGgBC1zlprexikKTz0wPlK3wlZgnwdkwVzEoJwOnq95smTrR9AcMZzQ/s320/mbtloading.gif') no-repeat left center;
width: 16px;
height: 16px;
}
.viewscount {
float: right;
color: #EE5D06;
font: bold italic 14px arial;
}
.views-text {
float: left;
font: bold 12px arial;
color: #333;
}
.views-icon{
background: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUgJucojsJCKass6HE556H0UIrXjKF7V0BYd_CNGCV3Z4KsIm4GIogAqyH-cPTBM0DlyY3PS64WrvplCEYSGEsf_zv83VZfDVk-hjoZwoEebi8ggPc0p9OpL6Q6V4DriIeep6Zw8pShgCF/s1600/postviews.png') no-repeat left;
border: 0px;
display: block;
width: 16px;
height: 16px;
float: left;
padding: 0px 2px;
}

Customization: 

  • Edit #EE5D06 to change the text color of the numeric count.

  • Replace right with left to change the plugin alignment.
  1. Now search for </body> and paste the following code just above/before it.

<!-- Post Views Script by MBT -->
<script type='text/javascript'>
    window.setTimeout(function() {
document.body.className = document.body.className.replace(&#39;loading&#39;, &#39;&#39;);
      }, 10);
  </script>
<script src='https://cdn.firebase.com/v0/firebase.js' type='text/javascript'/>
<script>
$.each($(&#39;a[name]&#39;), function(i, e) {
var elem = $(e).parent().find(&#39;#postviews&#39;).addClass(&#39;mbtloading&#39;);
var blogStats = new Firebase(&quot;https://bloggertipstricks.firebaseio.com/pages/id/&quot; + $(e).attr(&#39;name&#39;));
blogStats.once(&#39;value&#39;, function(snapshot) {
var data = snapshot.val();
var isnew = false;
if(data == null) {
data= {};
data.value = 0;
data.url = window.location.href;
data.id = $(e).attr(&#39;name&#39;);
isnew = true;
}
elem.removeClass(&#39;mbtloading&#39;).text(data.value);
data.value++;
if(window.location.pathname!=&#39;/&#39;)
{
if(isnew)
blogStats.set(data);
else
blogStats.child(&#39;value&#39;).set(data.value);
}
});
});
</script>

Change the highlighted orange line with your firebase URL which you copied instep 4.
  1. Now find this code:

<data:post.body/>

Just above this paste the following code

<!-- Post Views Counter by MBT-->
<div id='views-container'><span class='views-icon'/><div class='views-text'>Views:</div> <div class='mbtloading viewscount' id='postviews'/></div>

Replace Views: with any text you want to use.
  1. Now paste the below code just after <head>

  2. <script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>

  3. Press save template button.
Congratulation! You have successfully installed the post views counter for your blog.



Tidak ada komentar:

Posting Komentar