Skip Navigation

[Resolved] Check if page has parent and use it's featured image

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to dispaly parent post featured image conditionally

Solution:
you can use [wpv-conditional] shortcode to dispaly conditional output.

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/check-if-page-has-parent-and-use-its-featured-image/#post-406904

Relevant Documentation:
https://toolset.com/documentation/views-shortcodes/#wpv-post-featured-image
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years, 10 months 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by David 7 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#406808

I am trying to test if a page's parent has a featured image and if so to use the parent's featured image. I expected either of the following code snippets to work but they aren't.

[wpv-conditional if="( '[wpv-post-featured-image id='$parent']' ne '' )"]
	[wpv-post-featured-image id='$parent' size='full' class='post-thumbnail']
[/wpv-conditional]

or...

[wpv-conditional if="( (empty('[wpv-post-featured-image id='$parent']')) )"]
	[wpv-post-featured-image id='$parent' size='full' class='post-thumbnail']
[/wpv-conditional]

I confirmed that the shortcode within the conditional does work on it's own but I've got something wrong with my conditional itself. Any help would be appreciated.

#406904

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I've tested this and following code is working at my end. Could you please try to use following code:

[wpv-conditional if="( '[wpv-post-featured-image output='url' id='$parent']' ne '' )"]
[wpv-post-featured-image id='$parent' size='full' class='post-thumbnail']
[/wpv-conditional]

I've used "output" attribute.

More info:
https://toolset.com/documentation/views-shortcodes/#wpv-post-featured-image

#407122

Yes, that worked, thank you! I needed to pay more attention to the specific parameters for the featured image shortcode. Again, thank you!

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