PHP code example of oberonlai / wp-page-template-loader
1. Go to this page and download the library: Download oberonlai/wp-page-template-loader library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oberonlai / wp-page-template-loader example snippets
use ODS\PageTemplateLoader;
$pageTemplates = new PageTemplateLoader();
$pageTemplates->addTemplate(
WP_PLUGIN_DIR . '/my-custom-plugin/templates/template1.php' => 'templateName1',
WP_PLUGIN_DIR . '/my-custom-plugin/templates/template2.php' => 'templateName2',
);
/**
* Add a new custom template.
*
* @param $template array of file path and template name
*/
public function addTemplate( Array $template )
{
foreach ( $template as $key => $value ) {
$key = str_replace('\\', '/', $key);
$this->templates[$key] = $value;
}
}