I’ve received a number of email’s and a couple of comments regarding the calculations I’m using to track my weight. Most the questions deal with how I’m displaying information from The Hacker’s Diet plugin on the front of my blog, so I figured I’d write a little how-to explaining what I’ve done.

First a quick caveat, while I’m going to try and make this as simple as possible, you’re going to have to know basic html in order make this work. But since you’re running your own blog, I’ll assume you can handle that. I’m also going to assume that you are familiar with the Hacker’s Diet plugin.

The Charts

This is the easy part. The plugin creates the charts using PHP, but the results are just images – meaning anywhere you can put an image tag, you could put a chart.

So, for instance, if you wanted to display the main chart you see when you enter your daily weight you would just have to put the following tag into your post or page:

  • <img src="http://www.[INSERT_YOUR_URL_HERE].com/wp-content/plugins/the-hackers-diet/hackersdiet_chart.php?user=1&weeks=2&goal=[INSERT_YOUR_GOAL_HERE]" />

If you’re like me, and your goal is so far away from your current weight that it makes the chart look cluttered and unreadable, you can remove the entire ‘&goal=[INSERT_YOUR_GOAL_HERE]’ portion of the URL to have the chart display only the relevant area.

If you want to change the time-frame the chart is looking at you have two options, first, you can simply change the number of weeks the chart is looking back, like so:

  • <img src="http://www.[INSERT_YOUR_URL_HERE].com/wp-content/plugins/the-hackers-diet/hackersdiet_chart.php?user=1&weeks=4" />

The other option is to replace the ‘&weeks=’ with start and end dates. So, if I wanted my chart to start on 04/28/09 and end on 05/28/09 I would use the following:

  • <img src="http://mywastedlife.com/wp-content/plugins/the-hackers-diet/hackersdiet_chart.php?user=1&start_date=2009-04-28&end_date=2009-05-28" />

There is no limit to the number of charts you can put on a page, and just about any script or tool you have to manipulate images (such as lightbox), should be usable.

Displaying Your Actual Weight, Weight Lost, Widgets, Etc.

This part is alittle more complex, if only because I’m not much of a programmer. It’s quick and dirty, but it seems to work, so I’ll share as best I can. (Note: I’ve no clue if this code creates potential security concerns in WordPress, so use at your own risk.)

First you’ll need to install the Exec-PHP plugin (or something similar) to enable you to execute PHP code on your pages/posts. Once you’ve done that, you can post the following into any post, page, or text widget you would like to use numbers from the database:

  • <?php
    $query = "select date, weight, trend from wp_hackdiet_weightlog order by date desc limit 1";
    $result = mysql_query($query);
    $dbweights = mysql_fetch_assoc($result);
    $weight_lost = [INSERT_YOUR_STARTING_WEIGHT_HERE]-($dbweights[trend]);
    ?>

You can now write your post as normal. Whever you would like to list your current weight, write the following:

  • <?php echo $dbweights[trend]; ?>

For example, on my progress page, I have the following sentence/code:

  • "I started at 325.6 lbs, and I currently weigh <?php echo $dbweights[trend]; ?>."

The same principle applies to the amount of weight you’ve lost. As long as you’ve put the weight you started at in the first block of code, you can use the following anywhere in the post/page to list how much you’ve lost:

  • <?php echo $weight_lost; ?>

So, as another example, the sidebar widget I’m using to list the amount of weight I’ve lost looks like this:

  • <?php
    $query = "select date, weight, trend from wp_hackdiet_weightlog order by date desc limit 1";
    $result = mysql_query($query);
    $dbweights = mysql_fetch_assoc($result);
    $weight_lost = 325.6-($dbweights[trend]);
    ?>
    <span style="font-size:38pt;"><?php echo $weight_lost; ?></span> lbs

In Conclusion

The charts are easy to pull off and you should be able to use those immediately. The PHP, well, I’ve no idea if that will work for you or not. I’m neither a WordPress guru, nor a PHP programmer. I’m just a tinkerer who was very motivated to make this work. But if you decide to follow this, and run into problems, leave a comment or shoot me an email and I’ll try and help as best I can.