WordPress条件语句如何排除多个页面模板以及分类归档页面
WordPress conditional statement how to exclude several page templates and also a taxonomy archive page
我的 header 中有代码排除了某些模板。我需要更改它以排除我的自定义 Post 类型的存档页面。存档模板的文件名为 taxonomy-press_category.php
.
但我不知道如何同时包含我的自定义 post 类型存档模板。
我目前正在使用:
if ( ! is_page_template ( array( 'homepage_template.php', 'services_template.php') ) )
我强烈建议先阅读“文档”。它会帮助您更快地回答您的问题!
"I need to change it to also exclude an archive page for my Custom Post type"
要排除存档页面,您可以使用 !is_archive()
和 !is_post_type_archive()
。要包含它,请删除 !
.
和
if (is_post_type_archive('name-of-your-custom-post-type')){
// Write your code
}
既然你提到了一些关于分类的东西,虽然还不清楚,is_tax()
可能是另一个可能有用的条件检查。
我再次强烈建议阅读“文档”,或者至少以清晰的方式包含您的问题的详细信息,以便人们可以更快地帮助您。
非常感谢您的参考,很有帮助。
这是最终对我有用的代码:
if( !is_page_template ('homepage_template.php') && !is_page_template( 'services_template.php' ) && !is_tax( 'press_category' )) {
我的 header 中有代码排除了某些模板。我需要更改它以排除我的自定义 Post 类型的存档页面。存档模板的文件名为 taxonomy-press_category.php
.
但我不知道如何同时包含我的自定义 post 类型存档模板。
我目前正在使用:
if ( ! is_page_template ( array( 'homepage_template.php', 'services_template.php') ) )
我强烈建议先阅读“文档”。它会帮助您更快地回答您的问题!
"I need to change it to also exclude an archive page for my Custom Post type"
要排除存档页面,您可以使用 !is_archive()
和 !is_post_type_archive()
。要包含它,请删除 !
.
和
if (is_post_type_archive('name-of-your-custom-post-type')){
// Write your code
}
既然你提到了一些关于分类的东西,虽然还不清楚,is_tax()
可能是另一个可能有用的条件检查。
我再次强烈建议阅读“文档”,或者至少以清晰的方式包含您的问题的详细信息,以便人们可以更快地帮助您。
非常感谢您的参考,很有帮助。
这是最终对我有用的代码:
if( !is_page_template ('homepage_template.php') && !is_page_template( 'services_template.php' ) && !is_tax( 'press_category' )) {