Created
November 18, 2015 00:31
-
-
Save jchamb/2c40fd589e1b485582c5 to your computer and use it in GitHub Desktop.
Wordpress template layouts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fx_layout_content() | |
{ | |
load_template( FX_Layouts::$main_template ); | |
} | |
function fx_layout_base() | |
{ | |
return FX_Layouts::$base; | |
} | |
class FX_Layouts | |
{ | |
/** | |
* Stores the full path to the main template file | |
* @var string | |
*/ | |
public static $main_template; | |
/** | |
* Stores the base name of the template file; e.g. 'page' for 'page.php' etc. | |
* @var string | |
*/ | |
public static $base; | |
public static function wrap( $template ) | |
{ | |
// stash the main template | |
self::$main_template = $template; | |
self::$base = substr( basename( self::$main_template ), 0, -4 ); | |
if ( 'index' == self::$base ) | |
self::$base = false; | |
/** | |
* Create template hierarchy layouts/{type}.php, layouts/master.php | |
*/ | |
$templates = array( 'layouts/master.php' ); | |
if(is_archive() || is_post_type_archive() || is_search() || is_tax()) | |
array_unshift( $templates, 'layouts/archive.php' ); | |
if ( self::$base ) | |
array_unshift( $templates, sprintf( 'layouts/%s.php', self::$base ) ); | |
// News & Events Archive | |
if( is_home() ) | |
array_unshift( $templates, 'layouts/blog.php' ); | |
if( is_single() ) | |
array_unshift( $templates, 'layouts/single.php' ); | |
return locate_template( $templates ); | |
} | |
} | |
add_filter( 'template_include', array( 'FX_Layouts', 'wrap' ), 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment