Simple Stats – Visitors Online

This post is designed to accompany Chapter 3 of my book, the WordPress-MU 2.7 Beginner’s Guide.

Would you like to show some simple stats in the sidebar of your WordPress-MU site?  Something like the stats in the screenshot below?

Visitor Stats

Visitor Stats

WordPress-MU makes it easy to pull information about the number of blogs and users that your site has, and display that information on the page, just use something similar to the following code.

<li id="Stats">
<h2>Site Stats</h2>
<ul>
<li><?php
$stats = get_sitestats();
echo "MYSITE.com currently has
<b>".$stats[ 'blogs' ]."
</b> blogs and
<b>".$stats[ 'users' ]."
</b> users."; ?></li>
</ul>

The above code will display the number of blogs that have been registered, and the number of user accounts that have been created.

If you’d like to show the number of visitors currently online, there are a number of ways you can do this.  The easiest is to use a simple visitor tracking script that will keep a count of recently active sessions.

Download this Simple visitor tracking script (right click and save as, then re-name the file to vonline.php).  This is a slightly edited version of a script that I’ve been using on my sites for a couple of years.  I did not write it, if anyone recognizes it, please let me know in the comments so I can give credit to the original author.

Upload the vonline.php file to your site (for simplicity, let’s pretend you put it in the same folder as your sidebar.php file – if you put it somewhere more central, then you will need to change the path used in the include statement to reflect that).

Then add the following line to the code listed above (place it just before the </ul> tag).

<li><?php include('vonline.php') ?></li>

Congratulations, now you have some visitor stats on your WordPress-MU blog home page!

Advertisements

One response to “Simple Stats – Visitors Online

  1. Pingback: Wordpress MU 自定义网站外观 (4) « WordPress MU 技术在线

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s