Skip Navigation

[Resolved] How to display placeholder image if image field is empty

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

Problem:
How to display placeholder image if image field is empty? In this particular case the client is showing user avatars.

Solution:
Insert both the image field, and the placeholder image.

Then wrap each of these in its own conditional statement that checks whether the image field is empty or not.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

This support ticket is created 6 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nashaat 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#909653

I have added a new custom user field for uploading a profile picture. I want that users upload and update their profile picture so that it shows on the custom frontend dashboard.

I have created content template and called it user profile (dashboard)! I use this template on every single page when user is logged in and it includes the picture field showing there. The problem is it doesnt matter if the user change or add a new photo, it will always show the same picture for all users. e.g if acount one add his profile picture then it updates on account one, account two, account three etc... All account has same photo even if 4 account are associated with different profile picture!

Field i am using in content template

[types usermeta='profile-picture' alt='%%ALT%%' title='%%TITLE%%' width='150' height='150' align='right' resize='crop' user_is_author='true'][/types]

What is the easiest way to achieve profile picture on the front end with user meta fields created with toolset? Is there anything i need to change?

Login: hidden link
Username: toolset
Password: Toolset

Thanks

#909657
profile-pic.png

Ok after submitted the ticket i just ave notices that i am using wrong code

This is wrong

user_is_author='true'

This works

user_current='true'

so it looks like this

[types usermeta='profile-picture' alt='%%ALT%%' title='%%TITLE%%' width='150' height='150' align='right' resize='crop' user_current='true'][/types]

one small issue i still have:

how can i show the general profile picture like attached, if usermeta='profile-picture' is empty. so if image field is empty it shows the gravatar picture and users will know that they can add their own picture!

#909703

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

You would need to use a conditional shortcode that tests whether the user field is empty or not.

It only works like "IF", there is no "ELSE", so you need two conditional statements, which essentially look like:

If the user field is not empty, show it.

If the user field is empty, show this image.

Using conditional shortcodes is introduced here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

You are specifically concerned with checking for empty values: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

#909742

Thank you Nigel! as you said i have used the conditional shortcode for that.

this is the right code

       [wpv-conditional if="( '[types usermeta='profile-picture' user_current='true' output='raw'][/types]' ne '' )"]
    	<div class="col-4 col-md-1 col-profile">
       [types usermeta='profile-picture' alt='%%ALT%%' title='%%TITLE%%' width='80' height='80' align='right' resize='crop' user_current='true' class="profile-img"][/types]
  	</div>
	[/wpv-conditional]

    [wpv-conditional if="( '[types usermeta='profile-picture' user_current='true' output='raw'][/types]' eq '' )"]
       HERE is basic Avatar Image
    [/wpv-conditional]
This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.