Hi there,
I'm making a website for an art gallery. Every artist (custom post type) is connected to some artworks (another custom post type). Each artwork has a repeatable field group, so that a given artwork can be associated with multiple images.
On each artist's page, there's a grid of thumbnails. The thumbnails originate from the first item in the repeatable field group of each artwork post.
In order to display the first item in the repeatable field group, I ended up having to create a view nested inside another view. Here's my question: is there a way to tell / test what page a view is being executed on? I want to change some CSS classes in the view's output based on the result of some conditionals.
Thanks!
Saul
Hi, you can use the special "$current_page" operator to set the context of a shortcode dynamically based on the page being loaded. Place this in any post View's loop to see how it works:
Current page: [wpv-post-id item="$current_page"]<br />
Current post in the loop: [wpv-post-id]
This technique works with Types field shortcodes as well. Let me know if you have questions about this implementation and I can give you more feedback.
Documentation for the "item" attribute:
https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/
Christian,
Thanks for your response. I think what I need to do is to determine whether a view has been called from a specific post type rather than a given post ID. Is that possible?
Saul
Yes, building on the previous example, you can use the $current_page operator in the wpv-post-type shortcode to determine the post type slug of the current page.
Current page post type slug: [wpv-post-type item="$current_page"]
Current loop item post type slug: [wpv-post-type]
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153408
Yes, this was the magic snippet I needed!
Thanks so much, Christian!
Saul