ParkourLabs.com REST API client and stack shortcodes
This is a small plugin to utilise the ParkourLabs.com REST API custom post types and their images. The provided shortcode will display a "stack" of images from those images.
1. Table of Contents
- 2.1. Built With
- 2.2. Installation
- 3.1.
[andyp_labs_stack]
- 3.2.
[andyp_labs_rest]
- 3.1.
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 "Stack" CSS-effect of images could be displayed to show the latest tutorial posts. To accomplish this, two parts needs to happen:
- ParkourLabs needed to extend it's REST API so that the custom post type and associated images could be queried.
- LondonParkour needed a shortcode to communicate with that REST API endpoint, pull the images and render them out in the "stack".
This plugin concentrates on the second part. It communicates with the API and pulls data.
2.1. Built With
This project was built with the following frameworks, technologies and software.
2.2. Installation
These are the steps to get up and running with this plugin.
- Clone the repo into your wordpress plugin folder
git clone https://github.com/IORoot/wp-plugin__REST--labs.git ./wp-content/plugins/ParkourLabs_REST_API_stack
- Insert one of the two shortcodes into your page.
[andyp_labs_stack] or [andyp_labs_rest]
3. Usage
There are two shortcodes available:
3.1. [andyp_labs_stack]
The [andyp_labs_stack]
shortcode can be used to automatically query the ParkourLabs.com REST API and render the image stack.
Just place wherever needed in your page.
This has a couple of features worth noting:
- It uses transients of one day. This is to cache the results.
- It styles the output based on the TailwindCSS Framework.
3.2. [andyp_labs_rest]
This shortcode allows for much more flexibility. There are six parameters that can be used to control the output.
- The number of results you wish to retrieve. Default is 5.
[andyp_labs_rest count="10"]
- The column of data to order the results. Default is "date"
[andyp_labs_rest order="date"]
- The posttype to actually search upon. The default is "tutorial".
[andyp_labs_rest posttype="post"]
- The category name to filter the results upon. The default is null.
[andyp_labs_rest category="demos"]
- The classes you wish to add to the resulting images. The default is empty.
[andyp_labs_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_labs_rest]
This is the title: {{post_title}}
[/andyp_labs_rest]
Using this shortcode allows you return multiple posts and display their details: e.g.
[andyp_labs_rest posttype="post" count="10" classes="w-10 rounded p-4 bg-gray-500"]
<h1>{{post_title}} : {{published_date}}</h1>
[/andyp_labs_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
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
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.
8. Contact
Author Link: https://github.com/IORoot
9. Changelog
v1.0.0 - initial version