admin管理员组文章数量:1130349
I have a site with multiple custom taxonomies which are used for filtering posts.
One of the taxonomies has a taxonomy-%term%.php template file.
/?country=the_country shows the country taxonomy template
but /?topic=the_topic&country=the_country uses the country taxonomy template as well.
Is there a simple way to avoid loading the taxonomy-country.php template if more than one taxonomy is being queried?
I have a site with multiple custom taxonomies which are used for filtering posts.
One of the taxonomies has a taxonomy-%term%.php template file.
/?country=the_country shows the country taxonomy template
but /?topic=the_topic&country=the_country uses the country taxonomy template as well.
Is there a simple way to avoid loading the taxonomy-country.php template if more than one taxonomy is being queried?
2 Answers
Reset to default 1See: Template Hierarchy
My suggestion would be to move away from term-specific template files in this case, and instead use only taxonomy.php, where in that file you can work out the logic you need to in order to render the proper output; i.e., you can then detect the use of multiple taxonomies and adjust as necessary.
The solution here was found by (as jaswrks has mentioned) removing the taxonomy-country.php file entirely.
The contents of taxonomy-country.php are then loaded conditionally within taxonomy.php
Custom post_types & taxonomies have an option to "rewrite" the urls. In this case, the same url parameters that are filtering the taxonomy archives were sometimes colliding with this url-schema and causing unwanted results.
The simple answer would be to disable rewriting the urls of the problem taxonomies.
But a cleaner option turned out to be to
remove_filter( 'template_redirect', 'redirect_canonical' );
... which can be used to disable the rewrite attribute from custom post_types or taxonomies
I have a site with multiple custom taxonomies which are used for filtering posts.
One of the taxonomies has a taxonomy-%term%.php template file.
/?country=the_country shows the country taxonomy template
but /?topic=the_topic&country=the_country uses the country taxonomy template as well.
Is there a simple way to avoid loading the taxonomy-country.php template if more than one taxonomy is being queried?
I have a site with multiple custom taxonomies which are used for filtering posts.
One of the taxonomies has a taxonomy-%term%.php template file.
/?country=the_country shows the country taxonomy template
but /?topic=the_topic&country=the_country uses the country taxonomy template as well.
Is there a simple way to avoid loading the taxonomy-country.php template if more than one taxonomy is being queried?
2 Answers
Reset to default 1See: Template Hierarchy
My suggestion would be to move away from term-specific template files in this case, and instead use only taxonomy.php, where in that file you can work out the logic you need to in order to render the proper output; i.e., you can then detect the use of multiple taxonomies and adjust as necessary.
The solution here was found by (as jaswrks has mentioned) removing the taxonomy-country.php file entirely.
The contents of taxonomy-country.php are then loaded conditionally within taxonomy.php
Custom post_types & taxonomies have an option to "rewrite" the urls. In this case, the same url parameters that are filtering the taxonomy archives were sometimes colliding with this url-schema and causing unwanted results.
The simple answer would be to disable rewriting the urls of the problem taxonomies.
But a cleaner option turned out to be to
remove_filter( 'template_redirect', 'redirect_canonical' );
... which can be used to disable the rewrite attribute from custom post_types or taxonomies
本文标签: templatesAvoid taxonomytermphp if more than one taxonomy
版权声明:本文标题:templates - Avoid taxonomy-%term%.php if more than one taxonomy 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749173035a2327340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论