Download the PHP package oberonlai/wp-template without Composer
On this page you can find all versions of the php package oberonlai/wp-template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oberonlai/wp-template
More information about oberonlai/wp-template
Files in oberonlai/wp-template
Package wp-template
Short Description Register and render templates from your plugin.
License MIT
Homepage https://github.com/oberonlai/wp-template
Informations about the package wp-template
PageTemplates
A simple class that allows registering WordPress any templates from plugins. Including page templates, custom post type templates and WooCommerce templates
Installation
Usage
First, initialize the class with the plugin's directory path and template folder. For example, if you place the template files in a folder which name is 'templates', you can assing the path.
Don't forget the last slash in folder path.
Add page template
Page template is the template can be used repeatedly in page editor. You can use to assign the page template. There are two arguments in :
- $file - The page template file name
- $name - Human-readable template name
Add page slug template.
Page slug template is the template for same slug name. You can use the template if your page slug's name is 'demo'. There are two arguments:
- $file The page template file name
- $slug For matched page slug
Add custom post type template
Custom post type template includes single and archive page. You can use the method to assign template file. There are three arguments :
- $file The page template file name
- $type Custom post type name
- $position Template position optional single, archive
Override WordPress template
WordPress template includes serveral filters to override.
https://developer.wordpress.org/reference/hooks/type_template/
You can use the method to assign template file. There are three arguments:
- $file The page template file name
- $position Template position
Override WooCommerce template
WooCommerce template has its own hierarchy. All you need to do is copy the WooCommerce template file you need to the template folder in your plugin.
You can use the method to change the default template path of WooCommerce. It will get the original template file if your plugin doesn't have the same name with WooCommerce template in templates/woocommerce path.
For example, if you have file in , wp-template will replace it.
Credits
The method was adapted from http://www.wpexplorer.com/wordpress-page-templates-plugin/