ArticlesForumDownload AboutContact

boakes.org

nice of you to drop by. tea?

Tags: Releases, WordPress

extending stattraq

September 24th, 2004, by Rich.

extending stattraq

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.

output from thre ViewCount pluginto 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

  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

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 />’ ); ?>

14 Responses to “extending stattraq”

Pages: «12

  1. 11
    Rich Says:

    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.

  2. 12
    Trackback from: Contraditorium » Os Plugins Secretos do Contraditorium
  3. 13
    Trackback from: Writer’s Blog » Blog Archive » Little Tweaks
  4. 14
    Trackback from: blog » Blog Archive » Plugins for WordPress

Pages: «12

Leave a Reply