2017 © Pedro Peláez
 

wordpress-plugin wp-template-hierarchy-everywhere

A WordPress plugin that implements the 'template hierarchy' concept for any template

image

picas/wp-template-hierarchy-everywhere

A WordPress plugin that implements the 'template hierarchy' concept for any template

  • Tuesday, November 1, 2016
  • by picas
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

The WordPress Template Hierarchy Everywhere

This plugin is an implementation of the "template hierarchy" concept of WordPress for any template., (*1)

It redefines some internal methods often used in templates to use the "template hierarchy" concept everywhere: for header, footer, sidebar, search form, sub-templates and assets., (*2)

Usage

Some new concepts & methods

The plugin first introduces a new concept: the ability to include a template passing it some arguments. This concept is just an enhancement of the get_template_part($slug, $name = null) internal function, with a third argument as an array of variables which will be loaded in the template:, (*3)

 get_template_part_fetch($slug, $name = null, $args = array())

Actually, the arguments are extracted in the current environment using the native extract() PHP function., (*4)

The plugin also defines a function to get an asset URI (a CSS or JS file for instance), searching it first in an optional child theme (if it exists) and falling back to the parent theme. This allows theme developers to let the final user overwrite one of the theme assets without modifying the original file (please note that this is not the same as overwritting a CSS rule in the child theme's style.css file as the original file of the parent theme will not be loaded in our case)., (*5)

This new function is:, (*6)

 get_asset_uri($name)

The template hierarchy in action

The smart stuff of the plugin is to introduce a new get_template_part_hierarchical() function on the same model as the classic get_template_part() with an implementation of the template hierarchy concept:, (*7)

 get_template_part_hierarchical($slug, $name = null, $include = true)

This function will search a template file following the same rules as for "root templates" (natively concerned by the template hierarchy) and finally fallback to the default WordPress behavior., (*8)

As for the enhanced version of including a template fetching it arguments described above, an enhanced version of this new function also exists:, (*9)

 get_template_part_hierarchical_fetch($slug, $name = null, $include = true, $args = array())

The template hierarchy aliases

As the core of WordPress does not allow to use its hooks to do so, you will have to use some new methods in replacement of common ones:, (*10)

original function new function
get_template_part() get_template_part_hierarchical()
get_footer() get_footer_hierarchical()
get_header() get_header_hierarchical()
get_sidebar() get_sidebar_hierarchical()
comments_template() comments_template_hierarchical()
get_search_form() get_search_form_hierarchical()

Have a look at the manual for a development of some of these features., (*11)

Installation

  1. Upload the plugin files to the /wp-content/plugins/wp-template-hierarchy-everywhere directory, or install the plugin through the WordPress plugins screen directly.
  2. Activate the plugin through the 'Plugins' screen in WordPress
  3. You're done

You can also embed a standalone version of this library in a plugin or a theme (internal tests will avoid multi-loading)., (*12)

Please see the releases of the repository to get last version (the master branch can have few commits forward but the last release is the best choice)., (*13)

NOTE - For those who are Composer users, the package is registered as picas/wp-template-hierarchy-everywhere., (*14)

Note for developers

As you will see, I do NOT follow the WordPress coding rules but the PSR (http://www.php-fig.org/). The WordPress rules just sucks. Period., (*15)

Support

If you find a bug, please use the support panel of the repository. You may first search in existing issues to check if the bug you figured has not been reported yet., (*16)

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version., (*17)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details., (*18)

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/., (*19)

This plugin is made "avec amour" from Paris, France., (*20)

WP_Template_Hierarchy_Everywhere
Copyright (c) 2016, Pierre Cassat

The Versions

01/11 2016

dev-master

9999999-dev https://github.com/e-picas/wp-template-hierarchy-everywhere

A WordPress plugin that implements the 'template hierarchy' concept for any template

  Sources   Download

GPL-3.0+

The Requires

 

The Development Requires

wordpress template theme template hierarchy

13/02 2016

v1.0.0-beta

1.0.0.0-beta https://github.com/e-picas/wp-template-hierarchy-everywhere

A WordPress plugin that implements the 'template hierarchy' concept for any template

  Sources   Download

GPL-3.0+

The Requires

 

The Development Requires

wordpress template theme template hierarchy