mercredi 15 juin 2016

Consuming a restful service from wordpress

I am a .net developer called in to assist with integrating a web api endpoint into a wordpress site.

So the endpoint returns JSON then I followed a tutorial that involved me building a guzzle plugin for wordpress and activating.

All good up to this point as I can see the plugin in wordpress plugin panel as activated.

Then followed some advice on creating a custom template as you will see below.

I copied the page.php from the twentyfifteen theme to my CustomePageT1.php template under the same theme directory.

I create a page into wordpress using this template and it just blanks.

I tried logging but can't see much.

Any advice or perhaps a new direction I can look into calling this API successfully?

I am totally lost as I used to HTML where I can inject a bit of Javascript to make this possible.

<?php /* Template Name: CustomPageT1 */

 use GuzzleHttp;

 get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

    <?php


    function getRecords(){
        // Try to get records
        $client = new GuzzleHttp('http://ift.tt/1VYRMX6');
        //$request = $client->get()->send();
        //print_r($request);
        //$records = json_decode($request->getBody(), true);
        //print_r($records);
    }

    getRecords();

    // Start the loop.
    while ( have_posts() ) : the_post();

        // Include the page content template.
        get_template_part( 'content', 'page' );

        // If comments are open or we have at least one comment, load up the comment template.
        if ( comments_open() || get_comments_number() ) :
            comments_template();
        endif;

    // End the loop.
    endwhile;
    ?>

    </main><!-- .site-main -->
</div><!-- .content-area -->



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire