REST API client for ParkourLabs CPT (isometric)<!-- --> | <!-- -->IORoot
logo
IORoot
WordPress
wordpress

ParkourLabs.com REST API client and Isometric shortcodes

This is a small shortcode to display an isometric view of images from the latest REST endpoint images.

1. Table of Contents

2. About The Project

This wordpress plugin was created to pull in the latest images from ParkourLabs.com into LondonParkour.com so that a nice "isometric" CSS-effect of images could be displayed to show the latest tutorial posts. To accomplish this, two parts needs to happen:

  1. ParkourLabs needed to extend it's REST API so that the custom post type and associated images could be queried.
  2. LondonParkour needed a shortcode to communicate with that REST API endpoint, pull the images and render them out in the "isometric" grid.

This plugin concentrates on the second part. It communicates with the API and pulls data.

(back to top)

2.1. Built With

This project was built with the following frameworks, technologies and software.

(back to top)

2.2. Installation

These are the steps to get up and running with this plugin.

  1. Clone the repo into your wordpress plugin folder
    git clone https://github.com/IORoot/wp-plugin__rest--isometric ./wp-content/plugins/ParkourLabs_REST_API_isometric
    
  2. Insert one of the two shortcodes into your page.
    [andyp_rest_isometric] or [andyp_isometric_rest]
    

(back to top)

3. Usage

There are two shortcodes available:

3.1. [andyp_rest_isometric]

The [andyp_rest_isometric] shortcode can be used to automatically query the ParkourLabs.com REST API and render the image isometric grid. Just place wherever needed in your page.

This has a couple of features worth noting:

  1. It uses transients of one day. This is to cache the results.
  2. It styles the output based on the TailwindCSS Framework.

3.2. [andyp_isometric_rest]

This shortcode allows for much more flexibility. There are six parameters that can be used to control the output.

  1. The number of results you wish to retrieve. Default is 5.
[andyp_isometric_rest count="10"]
  1. The column of data to order the results. Default is "date"
[andyp_isometric_rest order="date"]
  1. The posttype to actually search upon. The default is "tutorial".
[andyp_isometric_rest posttype="post"]
  1. The category name to filter the results upon. The default is null.
[andyp_isometric_rest category="demos"]
  1. The classes you wish to add to the resulting images. The default is empty.
[andyp_isometric_rest classes="w-10 block rounded"]

6 The content is anything that's between and opening and close tag. This allows for {{moustache}} brackets to substitute any post column to substituted for its value:

[andyp_isometric_rest]
    This is the title: {{post_title}}
[/andyp_isometric_rest]

Using this shortcode allows you return multiple posts and display their details: e.g.

[andyp_isometric_rest posttype="post" count="10" classes="w-10 rounded p-4 bg-gray-500"]
    <h1>{{post_title}} : {{published_date}}</h1>
[/andyp_isometric_rest]

4. Customising

You can simply change the endpoint in the code here:

https://github.com/IORoot/wp-plugin__REST--labs/blob/master/src/REST/labs_rest.php

Line 20:

public $endpoint = "https://parkourlabs.com/wp-json/wp/v2";

https://github.com/IORoot/wp-plugin__REST--labs/blob/master/src/REST/labs.php Line 14

public $endpoint = "https://parkourlabs.com/wp-json/wp/v2";

5. Troubleshooting

If the site is not picking up the JSON and images delete the transients using the WP CLI tool.

sudo -u www-data wp transient list
sudo -u www-data wp transient delete labsrest-blog
sudo -u www-data wp transient delete labsrest-demonstration
sudo -u www-data wp transient delete labsrest-tutorial
sudo -u www-data wp transient delete labsstack

(back to top)

6. Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

7. License

Distributed under the MIT License.

MIT License

Copyright (c) 2022 Andy Pearson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(back to top)

8. Contact

Author Link: https://github.com/IORoot

(back to top)

9. Changelog

v1.0.0 - initial version