Bitcoin Price Cached for 30 seconds
$29,280.61
Random Quote Cached for 30 seconds
"By believing passionately in something that does not yet exist, we create it."
Nikos KazantzakisExample 1: Latest Binance price
In the first example we are connecting to the Binance API to get the latest Bitcoin price. We have written a step by step guide on how we have done this. We have also used the Pro Plugin to cache the call for 30 seconds, just to avoid hitting the Binance API too often.
Example 2: Random quotes
In the second example we are connecting to the Quotable API to return a random quote. You can find details on this API at https://github.com/lukePeavey/quotable. We have also used the Pro Plugin to cache the call for 30 seconds.
Code Snippet
The code snippet below is the exact code we are using in this demo page. It demonstrates the use of the template tag function for easily outputting and formatting data.
<div class="tile-row">
<?php // do our api calls
$price = wpgetapi_endpoint( 'binance', 'price', array('debug' => false) );
$quote = wpgetapi_endpoint( 'quotable', 'random', array('debug' => false) );
?>
<div class="demo-tile binance">
<div class="internal">
<h4>Bitcoin Price <span>Cached for 30 seconds</span></h4>
<p>$<?php echo number_format( $price['price'], 2 ); ?></p>
</div>
</div>
<div class="demo-tile quote">
<div class="internal">
<h4>Random Quote <span>Cached for 30 seconds</span></h4>
<p>"<?php esc_html_e( $quote['content'] ) ?>"</p>
<span><?php esc_html_e( $quote['author'] ) ?></span>
</div>
</div>
</div>