Skip Navigation

[Resolved] Display Conditions if Post in View Matches the Current Page

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 7 months, 1 week ago.

Assisted by: Waqar.

Author
Posts
#2697682

I have a related products View on a single product page layout that I wish to display conditional styles based on if the post in the View output matches the current page.

I have the view built out (hidden link) and you can see what I'm attempting to replicate from the mockup here: hidden link

I suppose I could work in a strictly CSS or jQuery solution, but I wanted to see if I could use Toolset's Conditional Arguments to conditionally display a class name in the loop output that specifically applies the styles I'm looking to apply. The class I'm intending on using is simply gonna be labeled "disabled" and I'm going to have the styles already worked into stylesheet.

Any help in this manner would be greatly appreciated. Thanks in advance!

#2697747

Hi,

You can use the attribute item="$current_page" in Toolset shortcodes, to get the information from the current page:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

For example, to get the ID of the current page, you can use the 'wpv-post-id' shortcode, like this:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-id


[wpv-post-id item="$current_page"]

The same shortcode can be used in the conditional statement in a view's loop to compare the current page's ID and the current loop result's ID:


<div [wpv-conditional if="( '[wpv-post-id]' eq '[wpv-post-id item="$current_page"]' )"]class="current"[/wpv-conditional]>
......
</div>

regards,
Waqar

#2698022

Brilliant! This works as advertised (hidden link). Thank you for the assistance.