Bitcoin Forum
May 02, 2024, 06:13:01 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Easy Wordpress Bitcoin Price Widget Using PHP Script  (Read 9323 times)
michaelsuede (OP)
Jr. Member
*
Offline Offline

Activity: 39
Merit: 1


View Profile
February 15, 2012, 04:48:43 PM
Last edit: February 16, 2012, 03:36:28 PM by michaelsuede
 #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: <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($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']);
 
?>

<br/>
<br/>
Last:&nbsp;<?php echo $mtgox_array['last'];   ?><br/>
High:&nbsp;<?php echo $mtgox_array['high'];   ?><br/>
Low:&nbsp;&nbsp;<?php echo $mtgox_array['low'];   ?><br/>
Avg:&nbsp;&nbsp;&nbsp;<?php echo $mtgox_array['avg'];   ?><br/>
Vol:&nbsp;&nbsp;&nbsp;<?php echo $mtgox_array['vol'];   ?><br/>


To see it in action (and to donate Wink ), visit my site:
http://www.libertariannews.org/
1714673581
Hero Member
*
Offline Offline

Posts: 1714673581

View Profile Personal Message (Offline)

Ignore
1714673581
Reply with quote  #2

1714673581
Report to moderator
1714673581
Hero Member
*
Offline Offline

Posts: 1714673581

View Profile Personal Message (Offline)

Ignore
1714673581
Reply with quote  #2

1714673581
Report to moderator
Bitcoin mining is now a specialized and very risky industry, just like gold mining. Amateur miners are unlikely to make much money, and may even lose money. Bitcoin is much more than just mining, though!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714673581
Hero Member
*
Offline Offline

Posts: 1714673581

View Profile Personal Message (Offline)

Ignore
1714673581
Reply with quote  #2

1714673581
Report to moderator
bitcoinspot.nl
Sr. Member
****
Offline Offline

Activity: 300
Merit: 250



View Profile WWW
February 15, 2012, 10:28:57 PM
 #2

Great,

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

cheers!

- bitcoinspot.nl - Alles over bitcoin! -
michaelsuede (OP)
Jr. Member
*
Offline Offline

Activity: 39
Merit: 1


View Profile
February 15, 2012, 10:48:23 PM
 #3

Great,

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

cheers!

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
Hero Member
*****
Offline Offline

Activity: 548
Merit: 502


So much code.


View Profile WWW
February 16, 2012, 07:06:40 AM
 #4

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 Offline

Activity: 39
Merit: 1


View Profile
February 16, 2012, 03:31:09 PM
Last edit: February 16, 2012, 04:22:16 PM by michaelsuede
 #5

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
Hero Member
*****
Offline Offline

Activity: 548
Merit: 502


So much code.


View Profile WWW
February 16, 2012, 04:24:10 PM
 #6

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 Offline

Activity: 39
Merit: 1


View Profile
February 16, 2012, 04:38:04 PM
 #7

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
Hero Member
*****
Offline Offline

Activity: 548
Merit: 502


So much code.


View Profile WWW
February 16, 2012, 04:58:02 PM
 #8

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
Hero Member
*****
Offline Offline

Activity: 714
Merit: 500


View Profile
February 16, 2012, 05:01:20 PM
 #9

thanks.

Raoul Duke
aka psy
Legendary
*
Offline Offline

Activity: 1358
Merit: 1002



View Profile
February 16, 2012, 05:09:16 PM
 #10

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
Hero Member
*****
Offline Offline

Activity: 548
Merit: 502


So much code.


View Profile WWW
February 16, 2012, 10:10:55 PM
 #11

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

Would you look at that!

michaelsuede (OP)
Jr. Member
*
Offline Offline

Activity: 39
Merit: 1


View Profile
February 17, 2012, 07:29:32 PM
 #12

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

Thanks 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 Offline

Activity: 1358
Merit: 1002



View Profile
February 17, 2012, 07:55:27 PM
 #13

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 Offline

Activity: 1022
Merit: 1000


Freelance videographer


View Profile WWW
February 18, 2012, 01:14:01 AM
 #14

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 Offline

Activity: 39
Merit: 1


View Profile
February 20, 2012, 07:25:20 PM
 #15

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
Sr. Member
****
Offline Offline

Activity: 300
Merit: 250



View Profile WWW
March 06, 2012, 02:01:04 PM
 #16

does anyone know a ticker for the bitcoin prices in Euro?

Greets!

- bitcoinspot.nl - Alles over bitcoin! -
Raoul Duke
aka psy
Legendary
*
Offline Offline

Activity: 1358
Merit: 1002



View Profile
March 06, 2012, 03:26:54 PM
 #17

does anyone know a ticker for the bitcoin prices in Euro?

Greets!

Replace the URL with https://mtgox.com/api/0/data/ticker.php?Currency=EUR

Or just append
Code:
?Currency=EUR
to the one that's already there.
bitcoinspot.nl
Sr. Member
****
Offline Offline

Activity: 300
Merit: 250



View Profile WWW
March 07, 2012, 07:41:16 AM
 #18

aah thanks Smiley

- bitcoinspot.nl - Alles over bitcoin! -
bitcoinpreneur
Newbie
*
Offline Offline

Activity: 30
Merit: 0



View Profile WWW
June 25, 2013, 11:43:58 PM
 #19

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 Smiley
JessyMatt
Full Member
***
Offline Offline

Activity: 191
Merit: 100



View Profile
January 25, 2014, 06:15:32 AM
 #20

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?

DISCIPLINA — The First Blockchain For HR & Education
From core developers of Cardano, PoS minting, unique Web Of Trust & Privacy algorithms. Be the first, join us!
  WEBSITE  TELEGRAM  ANN  BOUNTY  LINKEDIN  WHITEPAPER  Referral Program 5%
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!