[Resolved] Setting a specific style for the current archive term in a WP archive view
This support ticket is created 4 years 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.
Tell us what you are trying to do? add a specific style to the active parent taxonomy item in the sidebar menu in taxonomy archive page of parent & child taxonomy for the custom taxonomy: "Product- categories".
Taking for example hidden link :
- [wpv-taxonomy-archive info='slug'] will return the slug of the term of the current archive: 'commercial'.
- [wpv-taxonomy-slug] will return the slug of the term inside the loop.
Once both are equal, we will add "current" to the class attribute of the
tag.
Then we can add a custom CSS style to the view to style the current category term:
I Have tested with the code you have provided but for some reason, it is not working. The class "current" is only getting applied to category item "commercial" on every page. Here is the HTML markup of the same: hidden link.
Can you please look into this Nand pls let me know if any additional info required.
Can I take a closer look at your views to investigate why?
Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
The sidebar view was cached, that's why the "class" current was only applied to the first category, cached from the first visit. Check this screenshot hidden link
I deactivate the cache for the view in both WordPress archives, and the class "current" is now correctly assigned to the current archive page term. Check this screenshot hidden link
Thanks, it seems to be working only on parent taxonomy page and not in child taxonomy page. Please help me with the following:
1. How to disable caching in views
2. How to make it work in a child taxonomy page (for eg: hidden link), Currently the conditional output not returning any value for the class. ref this screenshot: hidden link
2. This is expected. The actual condition checks the terms of the sidebar view item against the current term(of the archive page) . If you want it to work for child terms, the condition should be updated. Conditions can be composed and nested. (condition1 or condition2), (condition3 and (condition4 or condition5)), etc.
This way, you can build, your own custom function or shortcode, that will use WordPress function get_term_parents_list to get all the parent terms and check inside the sidebar loop if the current item is a parent. You may use PHP functions explode and in_array.
- https://developer.wordpress.org/reference/functions/get_term_parents_list/
- hidden link
- hidden link