Tags: Releases, WordPress
extending stattraq
September 24th, 2004, by Rich.

one of the most useful things that stattraq author randy has done (apart from writing stattraq) is write up a few words about hacking wordpress. and as a kind of review of these notes, i had a go at knocking up a wordpress plugin that makes a database query. i wrote my first wordpress plugin yesterday, so this is my second. it’s the first one i’ve done that accessed the db, and the first one that i’ll stick out into the real world.
my requirements:
along with the normal metadata which can be seen about any post, i’d like to be able to show how many times that post has been viewed. additionally, by default, i want this information to be restricted to administrators.
to cut a not very long story short, it works. there were a few teething troubles as i worked out how to get the current post ID - and there may be a better way of generating the relative url (please comment if you know of one), but aside from that, i’m a happy bunny because i get my home page, and every posting, with integrated live usage stats.
Installation
Download this file- Rename it viewcount.php and copy it to your
/wp-content/pluginsfolder. - using wp-admin, enable the plugin
Usage
In my index.php file, within the loop, and in amongst all the other metadata code, I use the plugin as follows.
<?php rjb_get_view_count( $post->ID, ”, ‘ views<br />’ ); ?>


March 30th, 2006 at 6:54 am
Hi Ktula, yes, that’s intentional. You can set the level below which readers are not allowed to see how many views there are.
<?php rjb_get_view_count( $post->ID, 'prefix', 'suffix', 0); ?>In this example I’ve set the admin level to 0, so it’s visible for everyone.
November 27th, 2006 at 12:35 pm
February 5th, 2007 at 9:05 pm
June 15th, 2007 at 10:56 am