Bitcoin Price Cached for 30 seconds
Random Quote Cached for 30 seconds
"Wisdom cannot come by railroad or automobile or airplane or be hurried up by telegraph or telephone."John Burroughs
Example 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.
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>