REST API client for ParkourPulse CPT<!-- --> | <!-- -->IORoot
logo
IORoot
WordPress
wordpress

ParkourPulse.com REST API client and stack shortcodes

This is a small shortcode to display a "stack" of images from the latest ParkourPulse images.

1. Table of Contents

2. About The Project

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

  1. ParkourPulse 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 "stack".

This plugin addresses the second part. It communicates with the API and pulls in the data. It then provides shortcodes to render them out.

(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--pulse ./wp-content/plugins/ParkourPulse_REST_API
    
  2. Insert one of the two shortcodes into your page.
    [andyp_pulse_stack] or [andyp_pulse_rest]
    

(back to top)

3. Usage

There are two shortcodes available:

3.1. [andyp_pulse_stack]

The [andyp_pulse_stack] shortcode can be used to automatically query the ParkourPulse.com REST API and render the image stack. 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_pulse_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_pulse_rest count="10"]
  1. The column of data to order the results. Default is "date"
[andyp_pulse_rest order="date"]
  1. The posttype to actually search upon. The default is "tutorial".
[andyp_pulse_rest posttype="post"]
  1. The category name to filter the results upon. The default is null.
[andyp_pulse_rest category="demos"]
  1. The classes you wish to add to the resulting images. The default is empty.
[andyp_pulse_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_pulse_rest]
    This is the title: {{post_title}}
[/andyp_pulse_rest]

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

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

4. Customising

You can simply change the endpoint in the code here:

https://github.com/IORoot/wp-plugin__REST--pulse/blob/master/src/REST/pulse_rest.php

Line 20:

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

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

public $endpoint = "https://parkourpulse.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 pulserest-pulse
sudo -u www-data wp transient delete pulsestack

(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