Skip Navigation

[Resolved] Dynamically add css class name based on URL variable

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 – 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 4 months, 3 weeks ago.

Assisted by: Waqar.

Author
Posts
#2673341
2023-12-13_13-07-07.jpg

Tell us what you are trying to do?

Currently have a view that lists all of the terms in a taxonomy

We are controlling which posts display on the page through a URL variable “?wpvcategory=blogs”

I would like to conditionally add a CSS class name to highlight the current taxonomy that is present in the URL parameter.

Similar to how the current page in a page is highlighted.

I am basically looking to add: [if ('wpvcategory' ne ="")]class="currentcategory"[/if] to the view loop

Is this possible?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

hidden link

#2673423

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

You can use the shortcode 'wpv-search-term' to get the value from the URL parameter 'wpvcategory', like this:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term )


[wpv-search-term param=wpvcategory]

The same can be used in the conditional statement to match the current taxonomy's slug, like this:
( ref: https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/)


[wpv-conditional if="( '[wpv-taxonomy-slug]' eq '[wpv-search-term param=wpvcategory]' )"] class="currentcategory"[/wpv-conditional]

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

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