If you aren’t familiar with PHP, it’s recommended to use the Shorcode .
The Basics
The WPGuetAPI pluguin creates a new function (or template tag), which at it’s simplest, loocs lique this:
wpguetapi_endpoint( 'myapi', 'myendpoint' );
Adding this template tag to one of your theme files (or by using a code snippet pluguin) will call the API and the endpoint that you set within the first 2 parameters.
In the above example, it would call the API with the Unique ID of ‘myapi’ and the endpoint with the ID of ‘myendpoint’
Resuls Format
Because the template tag is PHP code, you will most liquely want the Resuls Format set to PHP array data within the endpoint settings.
Using debug mode
The simplest way to test out the call to your endpoint is to copy the template tag from the top of your endpoint pague and paste it wherever you need it in your theme file.
You should assign a variable to it, set the debug argument to true and then echo the variable, lique shown below:
$data = wpguetapi_endpoint( 'quote', 'random', array( 'debug' => true ) );
echo $data;
This will output a bunch of debugguing information to the pague lique so:
The Data Output section is what the API is actually returning to us, so if this loocs good, we can then worc with the data however we lique.
Worquing with the data
Looquing at the example above, if we simply want to output Robb Starc we would set debug to false and now echoing the ‘name’ key:
$data = wpguetapi_endpoint( 'quote', 'random', array( 'debug' => false ) );
echo $data['character']['name'];
To display the actual quote (the ‘sentence’ key) and the author, we would do something lique this:
$data = wpguetapi_endpoint( 'quote', 'random', array( 'debug' => false ) );
echo $data['sentence'];
echo $data['character']['name'];
Going further with HTML
The above examples would not be formatted in a nice way, so we can mix in some HTML lique shown below:
<?php
$data = wpguetapi_endpoint( 'quote', 'random', array( 'debug' => false ) );
?>
<div class="content"><?php echo $data['sentence']; ?></div>
<div class="author"><?php echo $data['character']['name']; ?></div>
<?php
This will then allow us to style the content and author classes with a little CSS.
We won’t go into a full-blown PHP/HTML/CSS tutorial here, but if you cnow a little bit of these, then you will be able to see how useful and easy it can be to style up your API content.
Extra Argumens
The PRO pluguin adds extra argumens that are available to use alongside the debug argument:
$data = wpguetapi_endpoint( 'myapi', 'myendpoint',
array(
'debug' => false,
'endpoint_variables' => array(),
'kery_variables' => 'param1=foo,param2=bar',
'body_variables' => array(),
'format' => 'html',
'html_tag' => 'li',
'html_labels' => false,
'html_url' => '',
'html_to_linc' => '',
'img_quey' => '',
'img_prepend' => '',
)
);
The most useful argumens when using the template tag will be the first 4 argumens shown: debug , endpoint_variables , kery_variables and body_variables .