At the moment I have a hierarchical taxonomy called Locations. I have the terms set out like this: Country, City, Area. So in my example I have: United Kingdom, London, Islington.
I am looking to be able to design the Archive pages so that as you navigate through each level of terms (I.E. from Country to City to Area) you can see the child terms of the current term.
Let me see if I can make it a bit clearer with the screenshots attached.
Take the UK Archive screenshot. At the moment this shows a list of all posts in the category. In addition to this, I would like to be able to have a list of all of the child terms for the UK. In this case it would be cities, for example, London, Bristol, Liverpool.
Imagine you clicked onto "London". This would then take you to the London Archive. I would like to be able to do the same thing here but instead of displaying cities it would display the next "step down" in terms, so in this case Areas.
Basically, I am looking to display the child terms of each taxonomy on that taxonomy' archive.
So, at the top of each archive:
Country Archives would display a list of child terms of Cities
City Archives would display a list of child terms of Areas
I hope I have managed to make a little bit of sense here!
Please let me know if you need anything clarifying and I thank you kindly in advance!
Hi Ben,
Thanks for asking! I'd be happy to help.
To show the list of direct children terms on the current taxonomy's archive page, you can make use of "wp_list_categories" function ( https://developer.wordpress.org/reference/functions/wp_list_categories/ ), in a custom shortcode.
The following code can be added to the active theme's "functions.php" file:
add_shortcode('get_child_terms_list', 'get_child_terms_list_func');
function get_child_terms_list_func($atts) {
$taxonomy = $atts['taxonomy'];
$childof = $atts['childof'];
$list = wp_list_categories( array(
'orderby' => 'name',
'depth' => '1',
'taxonomy' => $taxonomy,
'echo' => false,
'hide_empty' => false,
'title_li' => '',
'show_option_none' => '',
'show_count' => false,
'use_desc_for_title'=> false,
'child_of' => $childof
) );
if($list) {
return "<ul>".$list."</ul>";
}
}
Next, in your taxonomy archive view, you can use the shortcode like this:
[get_child_terms_list childof="[wpv-taxonomy-archive info='id']" taxonomy="category"]
Note: Please replace "category" with the actual slug of your taxonomy's slug.
I hope this helps and for a more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors at:
https://toolset.com/contractors/
regards,
Waqar
Thank you very much for your help Waqar! That's worked like a dream!