$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>templates - Avoid taxonomy-%term%.php if more than one taxonomy|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

templates - Avoid taxonomy-%term%.php if more than one taxonomy

matteradmin6PV0评论

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?

Share Improve this question asked Nov 7, 2017 at 20:08 admcfajnadmcfajn 1,3262 gold badges13 silver badges30 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

See: 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

Post a comment

comment list (0)

  1. No comments so far