Would you like your friends to see how you’re doing in NaNoWriMo without having to look at a page other than your truly awesome blog? Well, I’m here to tell you how to do it the wrong way.
You heard that right, people. This is not the right way to do it. I mean, it works. You can see that on the side of the page. But it’s a hackity hack.
If you feel like putting more than 15 minutes into the entire process, you can come up with a better option. But if not, just drop this into your sidebar.
One note: Dreamhost doesn’t let you use the php file() method to get external URLs by default, so there’s a little hack in there to turn the option on, then turn it back off. If you’re not on Dreamhost, this may not be necessary. The methods to remove are the init_set() methods. Just so you know.
<?php // Allow file() to open urls. ini_set('allow_url_fopen', '1');
// Replace the url here with your own NaNoWriMo API url. // Just log in, go to Fun Stuff->Word Count API and you can get it there. $result = file('http://www.nanowrimo.org/wordcount_api/wc/418267');
// This is the hack part of the hack. The results come back in an array, // and I hardcoded the correct index for the word count. There is probably // a better overall way to do this. I don't care. echo("I've written " . $result . " of 50,000 words.");
// turn back off letting file() open urls. ini_set('allow_url_fopen', '0'); ?>