Problem: I would like to use different WordPress Archive templates to display archives for terms in a single taxonomy, based on the term's hierarchy.
Solution:
Create 3 different WordPress Archives, one for each hierarchical level in your taxonomy. Use the wpv_filter_force_wordpress_archive filter to conditionally apply each template based on the taxonomy term's hierarchy. Example:
function get_tax_level($id, $tax){ $ancestors = get_ancestors($id, $tax); return count($ancestors)+1; } add_filter( 'wpv_filter_force_wordpress_archive', 'switch_tax_archive_by_level', 30, 2 ); function switch_tax_archive_by_level( $wpa_assigned, $wpa_loop ) { $wpa_to_apply = $wpa_assigned; $current_term_level = get_tax_level(get_queried_object()->term_id, get_queried_object()->taxonomy); if ($current_term_level == 1) { // show top-level archive $wpa_to_apply = 123; } else if ($current_term_level == 2) { // show mid-level archive $wpa_to_apply = 456; } else { // show third-level archive $wpa_to_apply = 789; } return $wpa_to_apply; }
Replace 123, 456, 789 with the IDs of each WordPress Archive and place the code in functions.php
Relevant Documentation: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 6 replies, has 2 voices.
Last updated by Christian Cox 3 years, 8 months ago.
Assisted by: Christian Cox.