Bitcoin Forum

Bitcoin => Project Development => Topic started by: LeGaulois on April 11, 2018, 05:29:15 PM



Title: Displaying the current Bitcoin price
Post by: LeGaulois on April 11, 2018, 05:29:15 PM
I need to install a code displaying the current Bitcoin price (and in future some other data related to Bitcoin)
I am using a WordPress installation.

So you may think, why not using the ready-made widgets such as coincompare bitcoinaverage and alike websites? I can't because they are branded (powered by.) And I can't use such method.

So then, why not to use APIs you say? Here is my problem:

How the fuck am I supposed to use the APIs?
I tried with different tags such as <src> <frame> and even I tried in a plain text (<==  :D Yes I know)

Using a search engine is not so useful, I mainly find links related to the WordPress API, not how to use APIs with WP.
I wasted 2 hours searching for something that I know it's easy to do (once you know how)

Thank you :'(


Title: Re: Displaying the current Bitcoin price
Post by: LeGaulois on April 14, 2018, 08:22:54 PM
Anyone?  ???


Title: Re: Displaying the current Bitcoin price
Post by: TryNinja on April 14, 2018, 08:39:16 PM
I'm not aware on how Wordpress works, but can you create a .PHP file and and host it in your website? You could create a .php file to parse out the price from an exchange/coinmarketcap/bitcoinaverage API and show it in your page (directly or through an iframe).


Title: Re: Displaying the current Bitcoin price
Post by: LeGaulois on April 14, 2018, 09:08:38 PM
Thanks dude. Yes, I can use PHP, so basically I create the file and just copy paste any API code inside and save? It's easy so, my only problem then is how to display it? is it what am I supposed to use on a page then?
https://www.google.com/search?q=how+to+call+a+php+function&oq=how+to+call+a+php+function&aqs=chrome..69i57j0l5.10327j0j7&sourceid=chrome&ie=UTF-8

through an iframe It didn't work but I think now I was using the URL and not an API code lol


Title: Re: Displaying the current Bitcoin price
Post by: bitcoinblog on April 15, 2018, 02:53:26 AM
If you want custom based then i can code for you in PHP which u can display anywhere u like

Or you can use readymade

https://wordpress.org/plugins/cryptocurrency-price-ticker-widget/

The keyword for search is Bitcoin Ticker or Cryptocurrency Ticker for wordpress.

https://wordpress.org/plugins/search/bitcoin-ticker-widget/


Title: Re: Displaying the current Bitcoin price
Post by: LeGaulois on April 17, 2018, 08:14:09 PM
Thanks for your offer but I prefer doing it myself as I am sure it isn't difficult. I don't want to use a plugin based solution as the WP installation I already overloaded with plugins which I usually don't like to have


Title: Re: Displaying the current Bitcoin price
Post by: TryNinja on April 17, 2018, 11:16:41 PM
Can you add your own PHP code inside the page?

If so, you could do something like this:

Code:
<?php  
  $url 
"https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=USD";

  
$json file_get_contents($url);
  
$data json_decode($jsonTRUE);

  
$btc_last  $data[0]["price_usd"];
?>


<ul>
   <li>Price: $<?php echo $btc_last ?></li>
</ul>

or if you can't, create a file called "price.php" or whatever with the same code and add something like this to your page:
Code:
<iframe width="300" height="300" frameBorder="0" src="price.php"></iframe>

or if you want to load it with Javascript and JQuery:

If you are not already using jquery in your page, add this to your <head> tag:
Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

And do something like this:
Code:
<div id="price"></div>

<script>
$(document).ready(function() {
    $("#price").load("price.php");
});
</script>


Title: Re: Displaying the current Bitcoin price
Post by: LeGaulois on April 18, 2018, 08:13:34 PM
Yeah, thanks buddy
Actually, both solutions will work. The first is the fastest I can include it in the theme, but I don't want to edit it as I am already facing a problem with it lol
The second one seems to be the best for my case, however, in


a PHP code can be included with <iframe.....src= ...>  ???


Title: Re: Displaying the current Bitcoin price
Post by: TryNinja on April 18, 2018, 08:30:30 PM
In this case, you are loading the price.php page into your iframe. So, the price will be printed in the price.php and shown in the page where you set the iframe code.