Hi,
What i try to show front end is a featured image. And if there is no featured image, i would love to use the conditional code to show another image. How do I use the conditional logic to display another image if there is no featured image?
Hi there,
Thank you for contacting us and I'll be happy to assist.
To conditionally show/hide content in your templates, you can make use of “wpv-conditional” shortcode.
We have a detailed guide on the topic at:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
For example, let's assume you have a custom image field with slug “backup-image”.
To conditionally show featured and back up images, you can add the shortcodes as:
[wpv-conditional if="( (!empty($(_thumbnail_id))) )"]
Featured image:
[wpv-post-featured-image size="thumbnail"]
[/wpv-conditional]
[wpv-conditional if="( (empty($(_thumbnail_id))) )"]
Backup image:
[types field='backup-image' title='%%TITLE%%' alt='%%ALT%%' size='thumbnail'][/types]
[/wpv-conditional]
The first conditional block will only show the featured image when it is set and the second block will only show the backup image when no featured image is set.
I hope this helps! Please let us know if you need any further assistance.
Regards,
Waqar