Skip Navigation

[Gelöst] How to display an image if there is no featured image?

This support ticket is created vor 5 Jahre, 7 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 Antwort, has 2 Stimmen.

Last updated by Waqar vor 5 Jahre, 7 Monate.

Assisted by: Waqar.

Author
Artikel
#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

Waqar
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

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

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