2
votes

after several hours of testing and development I need your help.

I've created a taxonomy with several (free) terms. After that I've created the page and sub pages for displaying the taxonomy, following the scheme from WordPress.

Following the hierarchy I need to create a page like taxonmy-{taxonomy}-{term}.php for every single term within my taxonomy. I need that subpages for a filter option.

Is there a way to create that subpages dynamically? The user creates terms by himself and I have no clue how they will be named.

Thanks for help.

2
so you need to filter by term that users will create? if not, taxonomy-{taxonomy}.php will be applied for all terms in that taxonomy. - Bojana Šekeljić
yes, I need to filter by terms created by users - Andre
and what does the filter do? - Bojana Šekeljić
The filter should show all items within this term. If you have articles from radio, print and television for example, the filter "radio" should show all posts within. - Andre
but why do you need template page for that if every term is not gonna need actual different template. simple tag loop should be enough - Bojana Šekeljić

2 Answers

1
votes

See this solution which hooks into the 'template_include()' filter. You'll check your specific taxonomy and redirect the $template at the end

    ....
    add_filter('template_include', array($this,'my_template_include'));
}

function my_template_include($template){
global $wp_query;
var_dump($wp_query);
return $template;
}
0
votes

I tend to write it like this, but generally @emeraldjava has it right

/********** Set Taxonomy Template ***********/
add_filter( 'template_include', 'tax-name_taxonomy_template' );
function tax-name_taxonomy_template( $template  ){
    if (is_tax('tax-slug')){
        $template = dirname(__FILE__).'/taxonomy-tax-slug.php';
    }
    return $template;
};