Skip Navigation

[Résolu] Indenting 3 levels deep Taxonomy with Views like how Cred displays on Post Forms

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: How to display taxonomy terms assigned to post hierarchical

Solution: To display the taxonomy terms assigned to post in hierarchical way, you can use custom shortcode and use standard wordpress function "wp_list_categories" to display terms hierarchically.

You can find proposed solution, in this case, with the following reply: => https://toolset.com/forums/topic/indenting-3-levels-deep-taxonomy-with-views-like-how-cred-displays-on-post-forms/#post-776948

Relevant Documentation: https://developer.wordpress.org/reference/functions/wp_list_categories/

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 contains 5 réponses, has 2 voix.

Last updated by Ronald E Il y a 3 années et 6 mois.

Assigned support staff: Minesh.

Auteur
Publications
#765246
view-inside.gif
view-main.gif
taxonomy-thru-view.gif
taxonomy-thru-cred.gif

I am trying to get a taxonomy loop to indent correctly as it only display the taxonomy links related to a Members Profile page. I have this setup with CRED and when I display the Taxonomy in a Post Form it displays correctly (taxonomy-thru-cred). When I try to recreate that layout on the live Members Profile Page it will not do it correctly.

Per this post https://toolset.com/forums/topic/i-need-to-display-the-custom-taxonomy-in-the-sidebar-using-the-same-hierarchy/ I tried setting up a view inside a view but it doesn't work like the guy said.

I used Test Expertise as the main view (view-main) and parent expertise (view-inside) to go inside and loop for the second and third level. It loops the right info but not in the right format or order and too many times on some.

Seems like Toolset knows how to do it since Cred renders the layout of this taxonomy correctly. How do I do it with Views on Member pages?

Thank you for your help,
Ronald E

#766824

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - what if you try to use following custom shortcode to display terms in bullet list order:

Please add following code to your current theme's functions.php file:

function list_hierarchical_terms($atts) {
    global $post;
    
    $taxonomy = $atts['taxonomy']; // change this to your taxonomy
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms.'&hierarchical=1&echo=0&style=list');
         
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

User shortcode as:

[display_post_tax_terms_hierarchical taxonomy="taxonomy-slug"]

Where:
- Replace 'taxonomy-slug' with your original taxonomy slug.

More info:
=> https://developer.wordpress.org/reference/functions/wp_list_categories/

#770644

Hi Minesh,

I did as you requested. I added the code to my functions.php in my bb-theme-child.
I put this code...

[display_post_tax_terms_hierarchical taxonomy="areas_of_expertise"]

...in my content template Single-membership, which is what the membership pages use, and nothing displays.

Was I suppossed to put in another location? Pleae let me know if you need admin rights to help.

Thank you,
Ronald E

#770646

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share problem URL and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#776948

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now. I've added following code to your current theme's functions.php file.

function list_hierarchical_terms($atts) {
    global $post;
     
    $taxonomy = $atts['taxonomy']; 
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms.'&hierarchical=1&echo=0&style=list');
          
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

If you check now at bottom of the page - I see its outputting correct results. I just added =========== to separate the results, you are welcome to remove it and adjust the output as per your need.
=> hidden link

#780604

Minesh, if you are ever in the Seattle area let me know and I will take you out to dinner to show my thanks for this beautiful piece of code.

Thank you so much,
Ronald E