admin管理员组文章数量:1318156
I have a movie review site, i would like to conditionally load the taxonomies of actors and directors only if a option of my theme is active. At the moment in the root theme folder I have these 2 files
taxonomy-actors.php
taxonomy-directors-php
I would like them to be used only if the function is active for example
if ($theme_comments == 1)
{
//load taxonomy-actors.php
} else {
//don't load taxonomy-actors.php
}
I have a movie review site, i would like to conditionally load the taxonomies of actors and directors only if a option of my theme is active. At the moment in the root theme folder I have these 2 files
taxonomy-actors.php
taxonomy-directors-php
I would like them to be used only if the function is active for example
if ($theme_comments == 1)
{
//load taxonomy-actors.php
} else {
//don't load taxonomy-actors.php
}
Share
Improve this question
asked Oct 23, 2020 at 13:16
Vincenzo PiromalliVincenzo Piromalli
1989 bronze badges
1 Answer
Reset to default 0Find the solution :)
Code:
if ($moviewp_comments == 1) {
add_filter( 'template_include', 'wpse_template_include' );
function wpse_template_include( $template ) {
// Handle taxonomy templates.
$taxonomy = get_query_var( 'taxonomy' );
if ( is_tax() && $taxonomy ) {
$file = get_theme_file_path() . '/templates/taxonomy-' . $taxonomy . '.php';
if ( file_exists( $file ) ) {
$template = $file;
}
}
return $template;
}
} else {
}
本文标签: How can i conditionally load taxonomytaxonomyphp template php files through functionsphp
版权声明:本文标题:How can i conditionally load taxonomy-{taxonomy}.php template php files through functions.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742041365a2417561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论