Skip Navigation

[Closed] Conditional Hierarchical Display of Taxonomy Categories and Sub-Categories Tree

This support ticket is created 3 years, 4 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.

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

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Raja Mohammed 3 years, 4 months ago.

Assisted by: Raja Mohammed.

Author
Posts
#1837983

I have a Custom Taxonomy for WooCommerce Products. The Taxonomy is "Bait Brands"

The Bait Brands have a hierarchical structure.

I want to setup a sidebar hierarchical menu tree but I only want the tree subcategories to display if the current taxonomy page is one of those subcategories or is a parent of the subcategory. I also want some conditional statements that will trigger CSS/HTML so that the current archive and parent archive names are bold.

So let's say we have this setup created in the admin area....

BAND BRAND1
- Sub-Brand 1-1
- Sub-Brand 1-2
- Sub-Brand 1-3
- Sub-Brand 1-4
- Sub-Brand 1-5
BAND BRAND2
- Sub-Brand 2-1
- Sub-Brand 2-2
- Sub-Brand 2-3
- Sub-Brand 2-4
- Sub-Brand 2-5
BAND BRAND3
- Sub-Brand 3-1
- Sub-Brand 3-2
- Sub-Brand 3-3

On the public side, if the current page is NOT one of the archive pages , then I want it to simply display the Parent Terms
BAND BRAND1
BAND BRAND2
BAND BRAND3

Then when a visitor clicks on one of the parent terms it takes them to that terms archive page. Let's say they click on BAND BRAND2.
So then the tree that gets displayed on the site should be...
BAND BRAND1
<b>BAND BRAND2</b>
- Sub-Brand 2-1
- Sub-Brand 2-2
- Sub-Brand 2-3
- Sub-Brand 2-4
- Sub-Brand 2-5
BAND BRAND3

So 2 things happened here... since BAND BRAND2 is the current archive, it needs to be bold.. and also all of the subcategories of BAND BRAND2 should appear. I don't want any of the subcategories of BAND BRAND1 or BAND BRAND3 to appear because neither of those are clicked.

I have been able to accomplish this so far with a simple nested view.

However, the problem arises when we need to go deeper... and a visitor clicks on one of the subcategories. Let's assume they click on Sub-Brand 2-2. Then I want the tree to be displayed as....

BAND BRAND1
<b>BAND BRAND2</b>
- Sub-Brand 2-1
- <b>Sub-Brand 2-2</b>
- Sub-Brand 2-3
- Sub-Brand 2-4
- Sub-Brand 2-5
BAND BRAND3

So now we are on the "2nd Level" of the menu tree... and the current archive name (Sub-Brand 2-2) is bold... the parent category name (BAND BRAND2) is also bold.

I have not been able to figure out how to use the conditional statements properly to get this accomplished when someone clicks on one of the subcategories (2nd level ) links.

I have searched all through your support forum.

Please help.

I am trying to emulate this page.... hidden link

#1839761

Raja Mohammed
Supporter

Languages: English (English )

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

Hello there,

It seems like you are already there

For the nested categories you can use the conditional with Contains that matches with the current post taxonomy terms .

[wpv-conditional if="( CONTAINS(#(taxonomy-slug), [wpv-taxonomy-id]) )"  ]
<strong> [wpv-taxonomy-link]</strong>
[/wpv-conditional]

For those terms the taxonomy display in normal text

[wpv-conditional if="( NOT(CONTAINS(#(taxonomy-slug), [wpv-taxonomy-id]) ) )"  ]
  [wpv-taxonomy-link] 
[/wpv-conditional]

taxonomy-slug = Is the taxonomy of the current post
[wpv-taxonomy-id = gets the taxonomy id from the taxonomy loop

You can use the same conditionals in both the view (in parent and child view loop) as the conditions checks for all taxonomies associated with the posts.

I hope this helps better.

Let me know if you need more clarification

Kind regards
Raja

#1840061

I still don't understand your solution.

In the "child taxonomy" archive pages, I need to have a conditional statement that searches the URL to determine if the current "Parent" taxonomy is contained in the URL and also if the current "Child" is contained in the URL.

Your solution of (taxonomy-slug) confuses me. That needs to be a variable. Seems like I should be using a custom code to check for the parent slug.

I even tried the debug="true" and it still doesn't shed any light on the situation.

Please help clarify. I can't find any documentation on the CONTAINS comparison for TOOLSET.

#1840769

Raja Mohammed
Supporter

Languages: English (English )

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

Sorry i missed the fact the request is to display on taxonomy archives,

You might need a custom function in the conditionals to check for the parent term when the child terms is displayed. In this way it is easy to manage the conditionals.

You can refer to the documentation on how to use custom functions with conditionals.
https://toolset.com/documentation/programmer-reference/views/using-custom-functions-in-conditions/

Regarding The CONTAINS function it takes two arguments one is the field value of the post and another is value to match with. In the example #(taxonomy-slug) replace the taxonomy-slug with the Bait Brands slug, The conditional will look for the taxonomy of the post. since you want this to be displayed on the archives page this condition may not work.

Let me know if you need more assistance on this reagard

Kind regards
Raja

The topic ‘[Closed] Conditional Hierarchical Display of Taxonomy Categories and Sub-Categories Tree’ is closed to new replies.