I want to show taxonomy in hierarchical order.
I used code from here https://toolset.com/forums/topic/taxonomy-order-2/#post-526921. It worked well but I also need to show the taxonomy in link format at a place. I tried passing format link but it didnt work.
Where can I find the parameters that can be passed? and how do I have option for name or link output?
Wish Toolset had option to display in hierarchical order instead of just Ascending or Descending by name.
Regards,
Sasank
Hello,
It does not need custom codes, you can setup a nested view for it.
For example, in a single post content,
1) Create a taxonomy view "parent-view":
- Query terms of your custom taxonomy
- filter by:
a) Select taxonomy terms whose parent is None.
b) Taxonomy is set by the page where this View is inserted
See screenshot: parent-filters.JPG
- in section "Loop Editor", within shortcode <wpv-loop>.. </wpv-loop>
display term's link shortcode [wpv-taxonomy-link] + below child view's shortcode
2) Create a taxonomy view "child-view":
- Query terms of your custom taxonomy
- filter by:
a) Select taxonomy terms whose parent is the value set by the parent view.
b) Taxonomy is set by the page where this View is inserted
See screenshot: child-filters.JPG
- in section "Loop Editor", within shortcode <wpv-loop>.. </wpv-loop>
display term's link shortcode [wpv-taxonomy-link]
You can also format both parent and child views by following our document:
https://toolset.com/documentation/user-guides/view-layouts-101/#the-output-formats
Hi,
Thank you for your reply.
The solution you gave seems to complicate things a bit going forward. The code mentioned here https://toolset.com/forums/topic/taxonomy-order-2/#post-526921 totally works as needed just that in someplace I want with link and other I want with link.
Can you point me towards how to modify it? I am not good at php and guess this is more of php to what I understood after searching a bit...
Regards,
Sasank
You can try to modify the PHP codes as below:
function list_hierarchical_terms($atts) {
$taxonomy = 'category'; // change this to your taxonomy
$separator = ', ';
$terms = wp_get_object_terms( get_the_ID(), $taxonomy, array( 'orderby' => 'term_id', 'order' => 'ASC', 'fields' => 'all') );
if ( is_wp_error( $terms ) || empty( $terms ) ) {
return;
}
$arr = array();
foreach( $terms as $term ) {
$arr[] = '<a href="' . get_term_link($term->term_id) . '">' . $term->name . '</a>';
}
return implode($separator, $arr);
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');
And test again
My issue is resolved now. Thank you!