michaelsuede (OP)
Jr. Member
Offline
Activity: 39
Merit: 1
|
|
February 15, 2012, 04:48:43 PM Last edit: February 16, 2012, 03:36:28 PM by michaelsuede |
|
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: <p><font color="red">xxxxxxxxxxxxxxxxx </font><p/>Thanks for contributing! <?php //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']); ?> <br/> <br/> Last: <?php echo $mtgox_array['last']; ?><br/> High: <?php echo $mtgox_array['high']; ?><br/> Low: <?php echo $mtgox_array['low']; ?><br/> Avg: <?php echo $mtgox_array['avg']; ?><br/> Vol: <?php echo $mtgox_array['vol']; ?><br/>
To see it in action (and to donate ), visit my site: http://www.libertariannews.org/
|
|
|
|
bitcoinspot.nl
|
|
February 15, 2012, 10:28:57 PM |
|
Great, i think i will tweak it a little and put it on www.bitcoinspot.nlcheers!
|
- bitcoinspot.nl - Alles over bitcoin! -
|
|
|
michaelsuede (OP)
Jr. Member
Offline
Activity: 39
Merit: 1
|
|
February 15, 2012, 10:48:23 PM |
|
Thanks. I was using those image widgets before but they kept on breaking because the site operators got lazy in maintaining them. This widget obviously pulls directly from Mt. Gox's API. So as long as Mt. Gox API is working, this widget will continue to work correctly. I also like it because I can format it however I want.
|
|
|
|
Clark
|
|
February 16, 2012, 07:06:40 AM |
|
I would cache this result with a timeout of a minute or so. You might even make it do an AJAX callback so your page loads faster.
Caching is needed because if you get visitors more often than every 10 seconds, then MtGox might start throttling/blocking you.
You need to do it asynchronously so that every page load doesn't have to talk to MtGox's server before delivering the final page to the user.
|
|
|
|
michaelsuede (OP)
Jr. Member
Offline
Activity: 39
Merit: 1
|
|
February 16, 2012, 03:31:09 PM Last edit: February 16, 2012, 04:22:16 PM by michaelsuede |
|
I would cache this result with a timeout of a minute or so. You might even make it do an AJAX callback so your page loads faster.
Caching is needed because if you get visitors more often than every 10 seconds, then MtGox might start throttling/blocking you.
You need to do it asynchronously so that every page load doesn't have to talk to MtGox's server before delivering the final page to the user.
That's a good idea, but more work than I'm willing to put into it at the moment. I suppose we can just leave this "as is" for low to medium traffic blogs, but it is worth noting that high traffic sites should cache these results. If someone updates the code snippet to cache against a MySQL database, I'll update the OP to include install instructions and the relevant code. Ideally this code should be wrapped in its own Wordpress widget and the MySQL script to setup the database cache should be set to install automatically with the install of the Widget from inside Wordpress, with the return variables from Mt. Gox being accessible by short code in the widget text field. This way people who have no technical knowledge would still be able to easily install the script. It might be worthwhile to not even limit the short code variable results to a widget, but rather make them accessible from anywhere on the site, such as in headers, footers or post content.
|
|
|
|
Clark
|
|
February 16, 2012, 04:24:10 PM |
|
That's a good idea, but more work than I'm willing to put into it at the moment.
I suppose we can just leave this "as is" for low to medium traffic blogs, but it is worth noting that high traffic sites should cache these results.
If someone updates the code snippet to cache against a MySQL database, I'll update the OP to include install instructions and the relevant code. Ideally this code should be wrapped in its own Wordpress widget and the MySQL script to setup the database cache should be set to install automatically with the install of the Widget from inside Wordpress, with the return variables from Mt. Gox being accessible by short code in the widget text field. This way people who have no technical knowledge would still be able to easily install the script.
It might be worthwhile to not even limit the short code variable results to a widget, but rather make them accessible from anywhere on the site, such as in headers, footers or post content.
It sounds like *somebody* needs to put together a suite of Wordpress plugins for various Bitcoin economic parameters: difficulty, # blocks, market cap, ticker.
|
|
|
|
michaelsuede (OP)
Jr. Member
Offline
Activity: 39
Merit: 1
|
|
February 16, 2012, 04:38:04 PM |
|
That's a good idea, but more work than I'm willing to put into it at the moment.
I suppose we can just leave this "as is" for low to medium traffic blogs, but it is worth noting that high traffic sites should cache these results.
If someone updates the code snippet to cache against a MySQL database, I'll update the OP to include install instructions and the relevant code. Ideally this code should be wrapped in its own Wordpress widget and the MySQL script to setup the database cache should be set to install automatically with the install of the Widget from inside Wordpress, with the return variables from Mt. Gox being accessible by short code in the widget text field. This way people who have no technical knowledge would still be able to easily install the script.
It might be worthwhile to not even limit the short code variable results to a widget, but rather make them accessible from anywhere on the site, such as in headers, footers or post content.
It sounds like *somebody* needs to put together a suite of Wordpress plugins for various Bitcoin economic parameters: difficulty, # blocks, market cap, ticker. That would be even more ideal hahah. Unfortunately my code expertise does not lie with PHP, but rather .Net, so I'm not well suited to undertake such a task. Perhaps someday I'll get around to learning the language and putting together a nice package like that. It would be nice if some pro-php people got around to this though. There's a lot of e-commerce and informational sites that could benefit from such a suite of Wordpress plugins.
|
|
|
|
Clark
|
|
February 16, 2012, 04:58:02 PM |
|
That would be even more ideal hahah.
Unfortunately my code expertise does not lie with PHP, but rather .Net, so I'm not well suited to undertake such a task.
Perhaps someday I'll get around to learning the language and putting together a nice package like that. It would be nice if some pro-php people got around to this though. There's a lot of e-commerce and informational sites that could benefit from such a suite of Wordpress plugins.
Should we set up a bounty?
|
|
|
|
finway
|
|
February 16, 2012, 05:01:20 PM |
|
thanks.
|
|
|
|
Raoul Duke
aka psy
Legendary
Offline
Activity: 1358
Merit: 1002
|
|
February 16, 2012, 05:09:16 PM |
|
Plugin based widget for wordpress. Just activate the plugin and you'll have the Bitcoin price Widget on your widget administration screen, ready to add to a sidebar of your choice. It's a little bit rough still, with no options to edit, but I'll probably change that in a couple days. It only took like 5 minutes to put this together. Download here: Clicky Clicky
|
|
|
|
Clark
|
|
February 16, 2012, 10:10:55 PM |
|
Plugin based widget for wordpress. Just activate the plugin and you'll have the Bitcoin price Widget on your widget administration screen, ready to add to a sidebar of your choice. It's a little bit rough still, with no options to edit, but I'll probably change that in a couple days. It only took like 5 minutes to put this together. Download here: Clicky ClickyWould you look at that!
|
|
|
|
michaelsuede (OP)
Jr. Member
Offline
Activity: 39
Merit: 1
|
|
February 17, 2012, 07:29:32 PM |
|
Plugin based widget for wordpress. Just activate the plugin and you'll have the Bitcoin price Widget on your widget administration screen, ready to add to a sidebar of your choice. It's a little bit rough still, with no options to edit, but I'll probably change that in a couple days. It only took like 5 minutes to put this together. Download here: Clicky ClickyThanks psy. This widget is basically just a rehash of the code I presented at the top of the page though, only you can't edit the way the info is displayed without editing the file. Not that I don't appreciate you putting it into a widget file format though. It would be nice to see a widget that incorporates caching and short code tags for the display of variables. Perhaps a customizable CSS as well.
|
|
|
|
Raoul Duke
aka psy
Legendary
Offline
Activity: 1358
Merit: 1002
|
|
February 17, 2012, 07:55:27 PM |
|
I just inserted your code in a plugin so it would be easier to add the widget and gave you credit for it. For caching people should use http://wordpress.org/extend/plugins/wp-widget-cache/ which will add options to set a timed cache to each widget individually. WP Widget Cache is not to replace the WP-Cache or WP Super Cache, it’s a plus for them. In the case of a high traffic site that should be already covered but it's a good thing you brought the subject up to the conversation.
|
|
|
|
film2240
Legendary
Offline
Activity: 1022
Merit: 1000
Freelance videographer
|
|
February 18, 2012, 01:14:01 AM |
|
This doesn't work on wordpress.com sites but the only thing that shows is the BTC address and text message,the php widget does not show.Just for those who use wordpress.com blogs.Seems that wordpress.com doesn't allow anything other than basic html on their site.
|
[This signature is available for rent.BTC/ETH/LTC or £50 equivalent a month] [This signature is available for rent.BTC/ETH/LTC or £50 equivalent a month] [This signature is available for rent.BTC/ETH/LTC or £50 equivalent a month]
|
|
|
michaelsuede (OP)
Jr. Member
Offline
Activity: 39
Merit: 1
|
|
February 20, 2012, 07:25:20 PM |
|
This doesn't work on wordpress.com sites but the only thing that shows is the BTC address and text message,the php widget does not show.Just for those who use wordpress.com blogs.Seems that wordpress.com doesn't allow anything other than basic html on their site.
Yeah I was afraid of that. Wordpress.com does block all scripting, to the point where you can't even embed video using standard embed code. They will allow Youtube shortcode embeds, but that's about it. The lack of script embedding on Wordpress.com is why I dumped that host for my own standalone in the first place.
|
|
|
|
bitcoinspot.nl
|
|
March 06, 2012, 02:01:04 PM |
|
does anyone know a ticker for the bitcoin prices in Euro?
Greets!
|
- bitcoinspot.nl - Alles over bitcoin! -
|
|
|
|
bitcoinspot.nl
|
|
March 07, 2012, 07:41:16 AM |
|
aah thanks
|
- bitcoinspot.nl - Alles over bitcoin! -
|
|
|
bitcoinpreneur
Newbie
Offline
Activity: 30
Merit: 0
|
|
June 25, 2013, 11:43:58 PM |
|
Thanks for all your early work in getting these widgets out there. We are in the process of releasing a suite of Bitcoin Plugins for WordPress and will definitely consider learnings from these earlier plugins in our best practices. Also just sent out a couple of tips
|
|
|
|
JessyMatt
|
|
January 25, 2014, 06:15:32 AM |
|
Can anyone tell me how to display latest prices for the top currencies in that one script like USD, CAD, Pounds, UR without having to have many copies of the script?
|
|
|
|
|