Navigation überspringen

[Gelöst] Display Conditions if Post in View Matches the Current Page

This support ticket is created vor 7 Monaten, 2 Wochen. 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 – 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)

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Waqar vor 7 Monaten, 2 Wochen.

Assistiert von: Waqar.

Author
Artikel
#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 (versteckter Link) and you can see what I'm attempting to replicate from the mockup here: versteckter 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 (versteckter Link). Thank you for the assistance.