Hello. Thank you for contacting the Toolset support.
To display such category/subcategory/post list. You need to follow the following steps.
1)
Create a taxonomy view of your taxonomy (Category). Name this view as "top-category-view"
=> Uncheck the checkbox "Don't show empty terms" at the section "Query Options"
=> Add following code to its loop output section [You can add fields as you wanted to loop output]:
<wpv-loop>
<a href="?taxonomy_id=[wpv-taxonomy-id]" target="_self" >
<h3 class="image-link-text">[wpv-taxonomy-title]</h3>
</a>
</wpv-loop>
2)
Add following code to your current theme's functions.php file:
add_filter( 'wpv_filter_taxonomy_query', 'func_filter_category_subcategory_posts', 99, 4 );
function func_filter_category_subcategory_posts($tax_query_settings, $view_settings, $view_id) {
if($view_id == 9999){
(!isset($_GET['taxonomy_id']))? $tax_query_settings['child_of']=0:$tax_query_settings['child_of'] = $_GET['taxonomy_id'];
}
return $tax_query_settings;
}
Where:
- Replace 9999 with your taxonomy view ID
3)
Create a new post View to list ALL posts belongs to the lowermost taxonomy term, say "view-posts-belongs-to-term"
=> Add new query filter from the "Query Filter" section for taxonomy as given under and save it, For instance, my taxonomy is "Product Categories"
Select posts with taxonomy: Product Categories slug in one of those set by the URL parameter wpvproductcat
eg. <em><u>hidden link</u></em>
=> add fields to display your post information as required at "loop output" section, for example [wpv-post-title] etc..etc.. and save the view
4)
Create a new page namely "Posts List" and add view "view-posts-belongs-to-term" created at step #3
5)
=> Add the following code to functions.php file or "Custom Code" section offered by Toolset.
add_filter( 'wpv_filter_taxonomy_post_query', 'func_list_post_or_taxonomy', 20, 4 );
function func_list_post_or_taxonomy( $items, $tax_query_settings, $view_settings, $view_id ) {
if($view_id == 9999){
foreach( $items as $item ) {
$children = get_term_children( $item->term_id, 'product_cat');
if(count($children)==0){
$display_posts =$_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST']."/posts-list/";
$item->name = '<a href="'.$display_posts .'?wpvproductcat='.$item->slug.'" target="_self" >'.$item->name.'</a>';
}else{
$item->name = '<a href="?taxonomy_id='.$item->term_id.'" target="_self" >'.$item->name.'</a>';
}
}
}
return $items;
}
Where:
- Replace 9999 with your original taxonomy view ID
- Replace 'product_cat' with your original taxonomy slug
6)
Create a new page and add the "top-category-view" view to list categories and it should work as per your need when you click on the taxonomy term link. Please let me know if you need further help.
You can add the code I shared either to functions.php file of your theme or "Custom Code" section offered by Toolset.
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/