Skip Navigation

[Resolved] How to display an image if there is no featured image?

This support ticket is created 6 years, 4 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
- 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 6 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1116443

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?

#1117173

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