Add a Visitor Counter to Your WordPress Blog

IMPORTANT NOTE: This Article Has Been Updated

We all want to know how we’re doing, right? One of the first things everyone wants to put on their website is a counter. I still remember in the mid-90s trying to find code that would let me put a counter on my site, each and every page.

Of course, web logs today are quite detailed, and you really don’t need a counter, but in case the urge is just too much, here’s a quick and simple counter for your WordPress page:

  • Edit your blog’s index.php file, and look for a place in the php to add code � right after this entry is a good place to start:

    require('./wp-blog-header.php');

  • At that point, add this code function:
    function displayCounter()
    {
      // simple php counter - copyright (c) 2005 D.Pankhurst
      // (BigBizBlog.com) free to use - just please keep copyright in
      $counternum=dirname($_SERVER['SCRIPT_FILENAME'])."/counter.txt";
      $counter="";
      if ( $fp = @fopen($counternum,'r+') ) // success?
      {
        $counter = fgets($fp,9);
        $counter=$counter+1;
        rewind($fp);
        fputs($fp,$counter);
        fclose($fp);
      }
      echo $counter;
    }
    
  • Now look through your php code for a place to display your counter. When you have a spot, add this code to the html there:

    <?php displayCounter(); ?>

    (Note: leave off the <?php and ?> if you want to place the code in a php section).

  • Now create an empty text file, and call it counter.txt
  • Upload your modified index.php file and the new counter.txt file – for safety, back up the old index.php file first.
  • Change the permissions on your text file � if Unix, you want to CHMOD the file to 777.

Now when you load the main page, you’ll have a text display of how often the page has been viewed. Be warned � this will be anytime an article is looked at, not just a main page view.

The code can be made quite fancy, with as many bells and whistles as desired � but for a simple, easy to use WordPress counter, it’s a great way to plug one in fast.

Have You Had a Near-Death Experience Lately?

For those of you regularly reading my blog, well you haven’t – at least for a while.

Oops, I’ll started again – you know the people that say ‘I need that like I need a hole in my head’ – sometimes they’re wrong…

Ok, Ok, so this is going nowhere fast. My point in writing today is simple – I wanted to explain what I was up to for a week, and as always see if there’s a nifty business lesson in there for all of us (as there was for me).

So here goes – a long time ago (close to a decade), I started losing my hearing in my left ear. Long story short, after about a dozen doctors, three operations (including a rather unsuccessful yet bloody one), I finally had a large tumor removed from my head, along with most of my inner ear.

For two years, now, I’ve been doing well, so well I figured that I was my usual invulnerable self and a tumor like that was a blip in the past. Unfortunately for me, my body didn’t share my confidence.

Last week I woke up with severe ear pain, like a bad ear infection. Over the weekend, it go worse – much worse. Whatever was upset inside seemed to be trying to aggressively get out – the left side of my head inflated about 3/4 inch, and as Monday drew near, the front of my face started puffing out as well.

Eventually, my ear had bulged itself out a complete 90 degrees, and the bowl part was facing forward.. I looked like a cartoon character (not the cool ones, the ones they have to put on late night television until someone learns to draw them better).

Rather than bore you with the details (poor/no sleep, counting every minute until my next painkillers, chills and sweats in rapid succession), I’ll just say that the last five days have been a somewhat less than pleasant experience.

But the changed on Wednesday. Strong antibiotics, a draining tube in my head, and lots of rest, and I may be past the worst of what really was a bad ear infection. It turns out that because of my previous surgery, I have this nice open area in my head just waiting for a bacteria party – and all the exit doors are locked. With nowhere to go, an infection can get it there, breed, and get really bad, really fast.

So sitting here writing this, with much less pain, and my noggin returning to standard size, it’s hard to remember I had anything to worry about – but I managed to scare my doctor, and he doesn’t scare easily. And he in turn scared me, which is also rare. So I feel I dodged a bullet. And of course this has been a wake-up call for me.

…which of course nicely segues into my other reason for posting this tonight – what does this have to do with you and your business?

Simple – most every adult today has had a ‘scary moment’ in their recent life, or at least knows someone who has. You know, the ‘what if this lump isn’t benign’ type.

Talk to someone with a migraine. Better yet, talk to a cancer survivor. What you’re looking for is that clarity of vision and focus that comes when a person is pretty sure this is it.

And ask yourself – if you were going to die next month, what would you focus on today? If you had 2 weeks? 1 week? 1 day?

In the movies, they talk about the long walks, and enjoying the sunset.

Forget that crap.

You’re terrified – terrified for the ones you leave behind, terrified someone won’t treat them as specially as they deserve to be treated, and sorry you won’t be there to protect them.

You’re sorry your business doesn’t pay enough, or that you wasted you time on the wrong opportunities, or that the investments you didn’t make won’t be there to help them. You’re upset about all the failures of yours that they’ll have to live with – and you think long and hard about how to reverse that if you have the chance again.

So, you have the chance. Don’t wait until you’re sick – take the thought experiment, and ask yourself, have you done what you needed to do? Are you? Are you going to?

It may sound grisly, but if my situation can benefit you, so be it. The chances are very good we’re all going to die – so it’s what you leave behind that’s worth that extra hard look.