Ubuntu / Linux news and application reviews.


Image Counter

Some website, such as blogspot.com (Blogger) are not written in PHP and there are no external tools for allowing us to add a post hit counter to this kind of website / blog. By post counter i mean: a visible counter that display (on the website, for every user to see) the number of views (page loads) of each individual post.

But here is a way to do this using an image counter (installation instructions for Blogger, but you can use it on any website):

Go to Layout > Edit HTML, click "Expand Widgets Templates", and copy this code:
Post views: <img alt='counter' expr:src='&quot;http://www.mortgagemeter.net/counter.php?page=&quot; + data:post.id + &quot;&amp;digit=v88&quot;' />

Where you want it to show up. I can't say exactly where because it depends on your theme, but to have it show when on a post page only (item), make sure it's under a line of code that looks like this:

<b:if cond='data:blog.pageType == &quot;item&quot;'>

And also it would make sense to be somewhere around: <data:post.body/>

If you do not use Blogger, use this code instead:
Post views: <img alt="counter" src="http://www.mortgagemeter.net/counter.php?page= + data:post.id + &digit=v88"/>

and replace data:post.id with something that will generate a unique number/text that is always the same for a particular post but different for each post, like I used the post id, or something similar. You can view a visitor counter demo under my posts. (only when clicking on a post, not on the main page!).


Update: there is no hosting plan to handle all the post views for all Web Upd8 readers which have installed this Blogger hack, so the only way around this would be for you to install the script on your own server / web host. Read how to do that, HERE.