Skip Navigation

[Resolved] Conditional statement if post has thumbnail

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 mikes-23 7 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#458824

I am trying to create altering layout in my list view depending whether or not a post has a featured image.

I figured this would work:

[wpv-conditional if="( '[wpv-post-featured-image]' eq '' )"]
            no image layout
[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-featured-image]' ne '' )"]
            has image layout
[/wpv-conditional]

but it does not. It works when there is no image, but when there is an image nothing between the conditional that checks for it not equalling null outputs.

I also added has_post_thumbnail to the custom functions list and tried this:

[wpv-conditional if="( has_post_thumbnail() eq 'true' )"]
              has image layou
[/wpv-conditional]

This also does not work.

How do I format the conditional so it outputs something only when post has an image?

#458862

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Could you please follow the following Doc to check featured image with [wpv-conditional] shortcode:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/
[Section: "Checking If A Post Has A Featured Image"]

For example:

[wpv-conditional if="( NOT(empty($(_thumbnail_id))) )"]
featured  image is available
 [/wpv-conditional]

[wpv-conditional if="( empty($(_thumbnail_id)) )"]
featured  image is empty
 [/wpv-conditional]

#459656

this works

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