Pages:
Author

Topic: Easy Wordpress Bitcoin Price Widget Using PHP Script - page 2. (Read 9357 times)

sr. member
Activity: 300
Merit: 250
Great,

i think i will tweak it a little and put it on www.bitcoinspot.nl

cheers!
jr. member
Activity: 39
Merit: 1
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:

Code:

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($chCURLOPT_REFERER'Mozilla/5.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
                
curl_setopt($chCURLOPT_USERAGENT"CakeScript/0.1");
                
curl_setopt($chCURLOPT_HEADER0);
                
curl_setopt($chCURLOPT_RETURNTRANSFER1);
                
curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
                
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
                
$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 Wink ), visit my site:
http://www.libertariannews.org/
Pages:
Jump to: