I just thought I would share this so that blog operators can easily add a modifiable BTC price widget to their Wordpress sites.
I'm not sure if this will work on a Wordpress.com hosted site, but it works fine on my stand-alone Wordpress installation.
High traffic blogs should take additional steps to cache the results from Mt. Gox or they may be throttled/blocked from updates by Mt. Gox. However, this widget should be suitable for most blog operators that don't have a regular viewership of more than several thousand page views per day.
To make this work, install the "PHP Code Widget" from the plugin gallery.
Widget can be found here:
http://wordpress.org/extend/plugins/php-code-widget/Then add the PHP Code Widget to your sidebar and paste this into the widget's text field. You can modify the text to display anything you like:
You can contribute to this site by making Bitcoin donations to: xxxxxxxxxxxxxxxxx
Thanks for contributing!
//first fetch the current rate from MtGox
$ch = curl_init('https://mtgox.com/api/0/data/ticker.php');
curl_setopt($ch, CURLOPT_REFERER, 'Mozilla/5.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch, CURLOPT_USERAGENT, "CakeScript/0.1");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$mtgoxjson = curl_exec($ch);
curl_close($ch);
//decode from an object to array
$output_mtgox = json_decode($mtgoxjson);
$output_mtgox_1 = get_object_vars($output_mtgox);
$mtgox_array = get_object_vars($output_mtgox_1['ticker']);
?>
Last: echo $mtgox_array['last']; ?>
High: echo $mtgox_array['high']; ?>
Low: echo $mtgox_array['low']; ?>
Avg: echo $mtgox_array['avg']; ?>
Vol: echo $mtgox_array['vol']; ?>
To see it in action (and to donate
), visit my site:
http://www.libertariannews.org/