Skip Navigation

[Resolved] Displaying taxonomies hierarchically

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1134519
screeshot-5.jpg
screeshot-4.jpg
screeshot-3.jpg
screeshot-2.jpg
screeshot-1.jpg

Hi,

I have a site where I need to show the different taxonomy terms (organs) on different levels (see screenshot-1).

So far, I've created a view that shows the taxonomy without any parent (i.e. first level, screenshot-2). In it, I show the taxonomy term and then I call another View to display some content ("Organes par taxonomie") (screenshot-3) and a third view that displays the sub-level taxonomies (ones who has a parent determined by the View). (screenshots 4).

The problem, as you see in screenshot-1, is that even if only the sub-taxonomy is selected (ex: "Reins"), the element is still visible in the parent (i.e. it is duplicated)... Ex: "Uretère (Ectoderme) (12.11)" should be only under "Vessie", but it is also visible under "Système urinaire"...

I've tried conditions to try to isolate that taxonomy id, but even when in the child is still has that id (ex: screenshot-5).

I see other posts where you talk about creating a code in function to be able to filter... a little mixed now...

How can I prevent the elements from the second level to be also visible in the first level? I.e. there is a way to filter elements with parents, but not elements with children...

Thank you.

#1134886

Hello,

Your screenshot isn't in English, it is hard to find the problem.

I assume we are talking about a hierarchical taxonomy, with terms:
- Système urinaire
-- Vessie
---- Uretère (Ectoderme)

I have tried it in my localhost with a fresh wordpress installation, it works fine, here are detail steps:
1) 1st level view query terms of taxonomy, filter by:
Select taxonomy terms whose parent is None.
display 2nd level taxonomy view

2) 2nd level taxonomy view filter by:
Select taxonomy terms whose parent is the value set by the parent view.
display 3nd level taxonomy view

3) 3rd level taxonomy view filter by:
Select taxonomy terms whose parent is the value set by the parent view.

There isn't the problem you mentioned above:
Term "Uretère (Ectoderme)" displays twice.

In case it is a compatibility problem, please deactivate other plugins, and switch to wordpress default theme 2017, and test again

If the problem still persists, please provide database dump file(ZIP file) of your website, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1135456

I guess what I would need is some kind of code for the first level that says to only show if there is not sub-level for that element.

Ex: if Element 1 is part of the first taxonomy, then show it, but if Element 2 is part of the first taxonomy (since it's hierarchical), but also of sub-taxonomy 1, then don't show it...

Or, even better, if there would be an option (like the actual checkboxes) to not show children elements... So, if I check both Taxonomy 1 and sub-taxonomy 1, it would show, but if I check only sub-taxonomy 1, then it would not show on first level...

#1135912

The database dump file you provided above is not valid, it seems produced by plugin "backupbuddy", which is not a free plugin, I don't have a copy in my localhost, I suggest you provide the database dump file by following out document:
https://toolset.com/faq/provide-supporters-copy-site/

For the question:
I guess what I would need is some kind of code for the first level that says to only show if there is not sub-level for that element.
What is the element? is it a post of custom post type?

If it is, I think it is possible, you can use [wpv-conditional] shortcode to check if this post is assigned to only one term, for example, you can try these:
1) Create a taxonomy view, query terms of custom taxonomy, filter by:
Select taxonomy terms whose parent is None.
Display below post view, and pass term slug to the post view's shortcode attribute "termslug", for example:
[wpv-view name="top-level-posts-only" termslug="[wpv-taxonomy-slug]"]

2) Create a post view, query posts of your custom post type, filter by:
Select posts with taxonomy:
Categories set by the parent Taxonomy View

in the view's loop, you can get parent term's slug with shortcode:
[wpv-attribute name="termslug"]
use it to check if it is an "Item with first level taxonomy only", like this:

[wpv-conditional if="'[wpv-post-taxonomy type="category" format="slug"]' eq '[wpv-attribute name="termslug"]'"]
[wpv-post-link]
[/wpv-conditional]
#1136541
screenshot.jpg

Thanks a lot Luo!

We're almost there...

Yes, these are custom types. If you still need the DB dumb, I'll try to provide it to you (don't have access to the server right now)...

I have modified slightly your code:
[wpv-conditional if="('[wpv-post-taxonomy type="category" format="slug"]' eq '[wpv-attribute name="termslug"]') OR ('[wpv-attribute name="termslug"]' eq '')"]

  • [wpv-post-link] <span class="feuillet">[wpv-view name="organe-feuillet-relationnel"]</span> ([types field='foyer-hamer'][/types])
  • [/wpv-conditional]

    That way, the second level (which is a second view and which doesn't provide a termslug) is also displayed...

    The only problem is (since nothing is ever easy) that sometimes an entry belongs to more than one taxonomy term (hopefully always on first level...). In that case, it's not "eq" to, say 'orl', but I guess it's "eq" to 'orl, sens' and sometimes more than two I guess... So, I tried to use "gte" or "lte" instead, but it doesn't work... Is there a way to say "includes" instead of "equals" (because my understanding is that "equals" must be identical, therefore if there are more terms, it's not equal anymore)?

    HERE'S THE SOLUTION I CAME WITH, but it's really not pretty, so if you have a better solution, I would like to see it...
    In the View that outputs the result, I replaced all your code by a script that I had to put directly in the output (i.e. not in the JS section), since I need to use a document.write:
    <script>
    var flag = false;
    var slugCat = '[wpv-post-taxonomy type="category" format="slug"]';
    if (slugCat == '') {
    flag = true;
    } else {
    var indexCat = slugCat.indexOf('[wpv-attribute name="termslug"]');

    if (indexCat >= 0) {
    flag = true;
    }
    }
    if (flag) {
    document.write('

  • [wpv-post-link] <span class="feuillet">[wpv-view name="organe-feuillet-relationnel"]</span> ([types field="foyer-hamer"][/types])
  • ');
    }
    </script>

    I needed to remove all the spaces and check the "Disable the wrapping DIV around the View" from the [wpv-view name="organe-feuillet-relationnel"] that it's calling, because it was breaking the JavaScript.

    So, like I said, now it's giving me the expected output (see screenshot), but the code is not too pretty...

    #1136573

    Thanks for share the solution, for the new custom JS codes problem:
    I needed to remove all the spaces and check the "Disable the wrapping DIV around the View" from the [wpv-view name="organe-feuillet-relationnel"] that it's calling

    I suggest you edit the view "organe-feuillet-relationnel", in the view's loop section and other section find and remove all spaces in it, you can also use JS codes to remove the spaces, for example:
    https://stackoverflow.com/questions/5963182/how-to-remove-spaces-from-a-string-using-javascript
    if you still need assistance for it, please create new thread for the new question, that will help other users to find the answers.

    This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.