Hi, sorry I am typically not available on Saturdays so I did not have a chance to reply yesterday. I'm looking at the site now, and I can see you have a nested View structure set up on this page:
hidden link
The parent View is "Impianti - Parent":
hidden link
The parent View loops over taxonomy terms in the taxonomy Categorie Impianti, where the term parent is None - in other words, top-level terms. In each result, you have displayed a nested View, Impianti - livello 1:
hidden link
This View loops over the terms whose parent is set by the parent taxonomy View. Each result in the livello 1 View is displayed with a link to the taxonomy term archive in the results.
I've set up the first level of categories but I don't understand how to create another view for the sub-categories level.
I can see that your livello 1 View is set up to include links to the taxonomy archive URL for each result. To design the taxonomy archive page, you can use Toolset's WordPress Archive feature. This allows you to design an archive for displaying information at the term archive pages like:
hidden link
hidden link
.. and so on for other terms. This archive can include a list of posts that are associated with the archive term, and it can also include a View of taxonomy terms like your livello 1 View. You can configure the taxonomy term filter so that it displays terms where the parent is the same as the current taxonomy archive term. This would allow you to display a list of child terms. I think this would work well for your scenario. You should create a WordPress Archive for the Categorie Impianti taxonomy. I think you should also create a View similar to the livello 1 View, but change the taxonomy term filter so that it displays terms whose parent term is the same as the current archive. Insert this View in your WordPress Archive for the Categorie Impianti taxonomy.
All the previous views have to be distinct kinds of views with different layouts and styles. Is this possible?
Toolset's WordPress Archives are assigned per taxonomy, not per hierarchical level. In other words, by default the same WordPress Archive is displayed for top level terms, sub-level terms, sub-level child terms, and so on. If you need to display a different WordPress Archive for different terms in the same taxonomy, you must use some custom code with our API filter wpv_filter_force_wordpress_archive:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive
I have some custom code snippets that might be useful here. For example, let's say you want to display a different WordPress Archive depending on the hierarchical level of a taxonomy term. Consider you have a custom taxonomy with the following terms and hierarchy:
Term 1
- Sublevel term 1
-- Sublevel child term 1
Term 2
- Sublevel term 2
-- Sublevel child term 2
Let's assume you have created 3 WordPress Archives, and you want to display different archives per level of the taxonomy, for example:
Term 1 - Display WP Archive A
- Sublevel term 1 - Display WP Archive B
-- Sublevel child term 1 Display WP Archive C
Term 2 - Display WP Archive A
- Sublevel term 2 - Display WP Archive B
-- Sublevel child term 2 Display WP Archive C
It sounds like this is similar to what you want to achieve, with a different design for the page based on the taxonomy hierarchy level. Here is the custom code snippet that can help you implement something like this:
/* ----------------------------------------------------------------------- */
// DIFFERENT WORDPRESS ARCHIVES PER LEVEL OF TAXONOMY TERM HIERARCHY
// https://toolset.com/forums/topic/nested-views-3/
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 ) {
$tax_slug = 'categoria-impianti';
$level_one_archive = 123;
$level_two_archive = 234;
$level_three_archive = 345;
$wpa_to_apply = $wpa_assigned;
$current_taxonomy = isset(get_queried_object()->taxonomy) ? get_queried_object()->taxonomy : null;
// only for one specific taxonomy
if( !$current_taxonomy || $current_taxonomy != $tax_slug )
return $wpa_to_apply;
$current_term_level = get_tax_level(get_queried_object()->term_id, $current_taxonomy);
if ($current_term_level == 1) {
// show top-level archive
$wpa_to_apply = $level_one_archive;
} else if ($current_term_level == 2) {
// show mid-level archive
$wpa_to_apply = $level_two_archive;
} else {
// show third-level archive
$wpa_to_apply = $level_three_archive;
}
return $wpa_to_apply;
}
You would change 123 to match the numeric ID of the WordPress Archive you want to display for top-level terms. You would change 234 to match the numeric ID of the WordPress Archive you want to display for the second level terms, and change 345 to match the numeric ID of the WordPrwess Archive you want to display for the 3rd level terms.
I can help you adjust this code as needed if you have more than 3 levels, just let me know.