boakes.org

ViewCount v0.0.3

As the number of page views rose I noticed a small deficiency in the ViewCount figures – it shows the number of times a page has been viewed, but this is not the same as the number of people who have viewed the page, and this is really what I wanted

[note: this plugin is an extension to stattraq - install that first]

the viewer counter in useI made a small modification to the sql so that it counts the distinct session id’s and therefore now shows the number of unique sessions which have viewed the page – so rather than telling you that a page has been viewed x times, it will tell you that it’s been viewed by y people – where y is any number less than or equal to x (i.e. where y=x each person has viewed the page just once).

Then Irelaised that it might be nice to have both capabilities (a) for informational purposes and (b) so as not to break the behaviour of the API (heh, look at me, one method and Im calling it an api).

Also, to ensure it didn’t grindon the server, i added an index on the session_id as follows: [sql]alter table wp_stattraq add index rjb (session_id);[/sql] – I’m going to assume and users can handle doing this using myphpadmin or mycc.

in case you’ve arrived here ready to cut ‘n’ paste without reading the rest… this plugin is an extension to stattraq – install stattraq first

Installation

  1. Download this fileDownload this file
  2. Rename it viewcount.php and copy it to your /wp-content/plugins folder.
  3. using wp-admin, enable the plugin

Usage

If you’re interested in finding the number of views for a particular post, then in the loop of your index.php file you might add the line:
<?php rjb_get_view_count( $post->ID, "", " views
" ); ?>

If you want to know how many distinct viewers the same post has had, you might use:
<?php rjb_get_viewer_count( $post->ID, "", " views
" ); ?>

Posted on September 30th, 2004 by Rich

Tags: