I want to list all posts with a corresponding template for a custom taxonomy term of a custom post type. To make it easier to understand:
The custom post type is called PUBLICATIONS and has a custom taxonomy called LISTS. Each list template is slighty different, so when all posts are listed on the archive-publications page, posts in term LIST A shall be displayed using Template A, LIST B Template B, and so on.
I've tried this:
<?php
function publikationen_archive() {
if ( is_archive('publikationen') && is_tax('downloads') ) { get_template_part( 'templates/content-downloads' );
} elseif ( is_archive('publikationen') && is_tax('sonderbaende-kataloge') ) {
get_template_part( 'templates/content-sonderbaende-kataloge' );
} elseif ( is_archive('publikationen') && is_tax('neuerscheinungen') ) {
get_template_part( 'templates/content-neuerscheinungen' );
} elseif ( is_archive('publikationen') && is_tax('untersuchungen') ) {
get_template_part( 'templates/content-untersuchungen' );
} elseif ( is_archive('publikationen') && is_tax('studien-materialien') ) {
get_template_part( 'templates/content-studien-materialien' );
}
} ?>
which didn't work. Then I came across the filter single_template
, template_redirect
and template_include
but don't really know what to do with them.
is_post_type_archive
is for checking if the view is a custom post type archive.has_term
is for checking if a post has a particular taxonomy term.