Problem: I would like to display a list of term archive links on hierarchical term archive page. The list should display the parent term and any sibling terms of the current archive term.
Solution:
- Create a View of the Product Category taxonomy. Add a term parent Query Filter, where the term parent is set by the parent taxonomy archive View. Make sure "Don't show empty terms" is unchecked if you want to show all sibling terms regardless of their post count.
- In the Loop Output of this View, insert the wpv-taxonomy link shortcode for now. We will come back to this to display the current term with a highlight.
- Create another View of the Product Category taxonomy. Add a term Query Filter, where the term ID is set by one shortcode attribute "terms".
- In the Loop Output of this View, insert the wpv-taxonomy link shortcode. This will display the parent term. After that, insert the View you created in step 1.
- Add this custom code to functions.php:
function get_term_parent_func($atts) { $a = shortcode_atts( array( 'taxonomy' => '', 'return' => 'id' ), $atts ); $taxonomy = $a['taxonomy']; $parent_id = 0; if( is_tax( $taxonomy ) ) { $taxObj = get_queried_object(); $tax = isset($taxObj->taxonomy) ? $taxObj->taxonomy : 0; $term = isset($taxObj->term_id) ? $taxObj->term_id : 0; $parent_slug = get_term_parents_list( $term, $tax, array('format'=>'slug', 'link'=>FALSE, 'inclusive'=>FALSE, 'separator'=>'')); if( $a['return'] == 'id' ) { $parent = get_term_by( 'slug', $parent_slug, $tax ); $parent_id = isset($parent->term_id) ? $parent->term_id : $taxObj->term_id; return $parent_id; } if( $a['return'] == 'slug' ) { return $parent_slug; } } return $parent_id; } add_shortcode("get_term_parent", "get_term_parent_func");
- Create the WordPress Archive for the child-level Product Category taxonomy, if it does not exist yet.
- In the Loop, insert your second View, the one with the Query Filter using a shortcode attribute. Use the custom shortcode to pass in the parent term's ID:
[wpv-view name="product-category-sidebar" terms="[get_term_parent return='id']"]
- Register get_term_parent in Toolset > Settings > Frontend Content > Third party shortcodes
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.
This topic is split from https://toolset.com/forums/topic/how-to-create-different-taxonomy-archive-page-for-parent-child-taxonomy-terms/
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 2 replies, has 2 voices.
Last updated by 6 years, 5 months ago.
Assisted by: Christian Cox.