So, I finally got around to updating my SparkStats Wordpress plugin. The original was a big hit, but over the past five months I’ve heard back from users about one big bug and lots of features that needed fixing and adding. Well, rejoice, because I finally took a break, sat down, and forced myself to incorporate all the feedback and release something new.
What is SparkStats, for those of you who’re wondering? Well, *ahem*:
SparkStats is a plugin for the Wordpress blogging platform. SparkStats uses the Sparkline PHP Graphing Library to generate word-like graphs that represent the posting and commenting activity on your blog over a period of days, weeks, or months. Sparklines are small, lightweight bits of graphical information, perfect for adding a little statistical information and visual style to your blog at the same time.
You can go and check out the newest version of the plugin over at my personal site where it’s hosted. Here’s a brief list of the new features:
- Bars can now represent days, weeks, or months.
- The background color can now be set via an option.
- The rendering interval can now be set via an option.
- A live preview of the current SparkStats graph is now included on the options page.
- “Invalid foreach” bug fixed.
In honor of this momentous occasion, I thought I’d walk you through installing the plugin and integrating it into your wordpress theme so that you don’t have any excuse not to try it out. Let’s give it a try, shall we?
Step One: Install The Plugin
First, you’ll need to download the latest version of the plugin to your local machine. Once you’ve got it, unzip the archive and use an FTP client to drop the “sparkstats” folder into your Wordpress plugins folder. In other words, the folder should now be located at *your Wordpress install*/wp-content/plugins/sparkstats/.

That was easy. Step one complete.
Step Two: Activate and Set Options
Next you need to activate your new plugin. It’s easy, just go to your Wordpress Admin area, click on “Plugins”, and then click the “Activate” in the SparkStats row.

Next, click on “Options” and then on “SparkStats” to access the SparkStats option screen. Here you will be able to see a preview of your current SparkStats graph as well as options for changing appearance, time scale, and rendering. In the graph, the height of each bar represents the number of posts made during that interval and the color represents the number of comments made. Play around with the options and click update to see how it will affect your SparkStats graph.

Step Three: Add to Template
Once you have your options set up to your liking, it’s time to add some code to your theme templates so that everyone who visits your site can see your SparkStats graph. It’s up to you where to add your graph into your page. I recommend the sidebar, and that’s what I’ll be showing you how to do here. With a little creativity, you could add the graph into your theme pretty much anywhere you wanted to.
Here’s a simple example of how to add the graph to the default theme sidebar. Just open the file located at *your Wordpress install*/wp-content/themes/default/sidebar.php and add the following code just below the search form li tag:
<li> Activity: Last < ?php sparkStats_numIntervals(); ?> < ?php sparkStats_intervalType(); ?><br /> <img src="<?php sparkStats_imgURI(); ?>" alt="SparkStats"/> </li>
Now you should have something that looks like this:

Easy, right? Now you can style the markup to your heart’s content. In addition, I’ve made it really easy to add an image of your own as a legend below the SparkStats graph in case you want to add your own legend (like we have over there on the right.) To add your own legend image, just upload the image as “statslegend.gif” into the SparkStats plugin folder. Then use
<img src="<?php sparkStats_legendURI(); ?>" alt="SparkStats Legend"/>
to include the image in your theme.
And You’re Done
Well, that was simple! Now you’ve got a bite-sized infographic about the activity of your blog. Don’t you look stylish? Tufte would be so proud.
Now you’ve got no excuse. Try SparkStats out on your own blog today and spread the word.





1
I don’t use Wordpress, but that’s awesome. Great effort on the plugin - it’s good to see not only the plugin itself, but perfect step-by-step instructions on how to install it. Nice job!
2
(Trackback)
Sam’s random musings » Installing the (New!) SparkStats Wordpress Plugin
[…] Installing the (New!) SparkStats Wordpress Plugin: […]
3
Great job. When I get my site up and going again I will use this plugin.
4
i’m a blogger user, but i really like this plugin.
5
How about a variation on your plugin that pulls data from a text file? (or better, perhaps, a specific blog posting that’s hidden. That way it’s easier to update the data.) I generate more miles on my bike than posts on my blog, so a graph of my mileage would be nicer. I can tinker with code a little… do you have some tips on what modifications would be needed?
6
(Post Author)
Sure, you could pretty easily do something like that Kurt. There’s a part of the plugin that actually generates the sparkline. You can see where I’m getting the numbers of posts and comments from MySQL and then passing the arrays into the sparklines library. If you wanted to use a different data source, that’s the part of the plugin that you’d want to change.
You can also just use the PHP Sparklines library seperately from the plugin if you’ve got a non-Wordpress site you want to integrate into (or if you find it easier than modifying the plugin.)
7
Just a note, in addition to your instructions, I had to change it so the sparkstats directory was writable by the server, so it could create and modify the sparkstats.png image. Nice plugin, also.