When we first started to submit the odd plugin to the WordPress plugin repository, we needed a means of providing an enhanced download link from our website. The answer came by way of a little download box with information sourced via the WordPress API. We wanted to include a title, basic description, download link, version details, and download count - and WP's API provides this. This article will provide you with the necessary WordPress shortcode that'll render an information download box in your WordPress page or post.
The result of our code is as follows:
The shortcode I used to generate this specific information was as follows:
There's a large amount of data returned via the WP API. To avoid hogging realestate we've added the update time and tested version text to the
Plugin Page links as link titles.
Copy and paste the WordPress function into your theme's
functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.
The image I've used can be downloaded from here . Alter it in your shortcode along with the background color and border style.
nameof your plugin is the only attribute that is required. While the plugin name is generally accepted, the plugin slug is preferred to avoid errors.
titleis optional. By default, the plugin title as used in the WordPress repository will be used. To use your own use
title="my title in here".
descriptionis optional. By default, the plugin title as used in the WordPress repository will be used. To use your own use
description="my description in here".
author="0"or alter your shortcode function.
number_format()function. If you choose not return the count in this manner, use
n="0"or alter the shortcode function.
trim="25". It's used so long descriptions don't run longer than is aesthetically pleasing.
bgcolor="#ffffff"or code a permanent change into the shortcode function.
border="#000000"or code a permanent change into the shortcode function.
cache & cache_error
cachetime refers to the time the result is cached. The
cache_errortime refers to the time you'll cache an error message before trying again.
The following PHP function may be used outside of WordPress. The primary differences are detailed below. Usage requires Simple Cache With PHP.
The primary difference between this and the WP version is that we truncate the description text to a character length - not a word count. If our means of truncation doesn't agree with you, select an alternative function here.
- You don't need to have anything to do with any of the plugins to be able to retrieve and display the data, making it an effective way of displaying information on review sites and blogs.
- For inactive plugins, consider using a longer cache period to avoid repeated requests to the WordPress API.
- A collection of the APIs used on the WordPress website are available here .