<?php | |
/** | |
* Return Archive Section | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/code/helper-function-for-template-include-and-body-class/ | |
* | |
* @param null | |
* @return string | |
*/ | |
function be_return_archive_section() { | |
if( is_post_type_archive( 'lifestyle' ) || is_tax( 'lifestyle-section' ) || is_tax( 'lifestyle-type' ) || is_tax( 'lifestyle-series' ) ) | |
return 'lifestyle'; | |
if( is_post_type_archive( 'recipe' ) || is_tax( 'name-range' ) || ( is_tax( 'base' ) && 'recipe' == get_post_type() ) ) | |
return 'recipe'; | |
if( is_post_type_archive( 'brand' ) || ( is_tax( 'base' ) && 'brand' == get_post_type() ) ) | |
return 'brand'; | |
if( is_post_type_archive( 'experience' ) ) | |
return 'experience'; | |
return false; | |
} | |
add_filter( 'template_include', 'be_template_chooser' ); | |
/** | |
* Template Chooser | |
* Use CPT archive templates for taxonomies | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/code/use-same-template-for-taxonomy-and-cpt-archive/ | |
* | |
* @param string, default template path | |
* @return string, modified template path | |
* | |
*/ | |
function be_template_chooser( $template ) { | |
if ( be_return_archive_section() ) | |
$template = get_query_template( 'archive-' . be_return_archive_section() ); | |
return $template; | |
} | |
add_filter( 'body_class', 'be_section_body_classes' ); | |
/** | |
* Section Body Classes | |
* @author Bill Erickson | |
* | |
* @param array $classes | |
* @return array | |
*/ | |
function be_section_body_classes( $classes ) { | |
if( be_return_archive_section() ) | |
$classes[] = 'section-' . be_return_archive_section(); | |
return $classes; | |
} |
This file contains 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