Adds single-items and archive-items on template hierarchy

This commit is contained in:
Leo Germani 2018-04-16 11:48:27 -03:00
parent 318ef7bdc3
commit 9b426bce89
1 changed files with 32 additions and 0 deletions

View File

@ -33,6 +33,9 @@ class Theme_Helper {
// make archive for terms work with items
add_action('pre_get_posts', array(&$this, 'tax_archive_pre_get_posts'));
add_action('archive_template_hierarchy', array(&$this, 'items_template_hierachy'));
add_action('single_template_hierarchy', array(&$this, 'items_template_hierachy'));
}
@ -148,6 +151,8 @@ class Theme_Helper {
// TODO: it would be better to do this via pre_get_posts. But have to find out how to do it
// Without generating a redirect.
// Another question is that, doing this way, hooking in wp, assures that the template loader
// still looks for tainacan-collection-single, and not for page.
global $wp_query;
$wp_query = new \WP_Query('page_id=' . $cover_page_id);
@ -160,5 +165,32 @@ class Theme_Helper {
}
function items_template_hierachy($templates) {
if (is_post_type_archive() || is_single()) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
$current_post_type = get_post_type();
if (in_array($current_post_type, $collections_post_types)) {
$last_template = array_pop($templates);
if (is_post_type_archive()) {
array_push($templates, 'tainacan/archive-items.php');
} elseif (is_single()) {
array_push($templates, 'tainacan/single-items.php');
}
array_push($templates, $last_template);
}
}
return $templates;
}
}