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.1. Built With
- 2.2. Installation
- 3.1.
[andyp_pulse_stack]
- 3.2.
[andyp_pulse_rest]
- 3.1.
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:
- ParkourPulse 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 addresses the second part. It communicates with the API and pulls in the data. It then provides shortcodes to render them out.
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--pulse ./wp-content/plugins/ParkourPulse_REST_API
- Insert one of the two shortcodes into your page.
[andyp_pulse_stack] or [andyp_pulse_rest]
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:
- It uses transients of one day. This is to cache the results.
- 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.
- The number of results you wish to retrieve. Default is 5.
[andyp_pulse_rest count="10"]
- The column of data to order the results. Default is "date"
[andyp_pulse_rest order="date"]
- The posttype to actually search upon. The default is "tutorial".
[andyp_pulse_rest posttype="post"]
- The category name to filter the results upon. The default is null.
[andyp_pulse_rest category="demos"]
- 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
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