Skip Navigation

[Gelöst] Display Images from Checkbox Values

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I would like to loop over the options for a checkboxes group field using Views, and display a different image per option.

Solution:
There is no built-in way to loop over checkbox options in a View, but you can use the syntax from the article below to write out some conditionals manually.

[wpv-conditional if="( '[types field='room-size' option='0'][/types]' eq 'filename1.jpg' )"]
    <img src="/wp-content/uploads/2019/04/filename1.jpg" />
[/wpv-conditional]
   
[wpv-conditional if="( '[types field='room-size' option='1'][/types]' eq 'filename2.jpg' )"]
  <img src="/wp-content/uploads/2019/04/filename2.jpg" />
[/wpv-conditional]
   
[wpv-conditional if="( '[types field='room-size' option='2'][/types]' eq 'filename3.jpg' )"]
  <img src="/wp-content/uploads/2019/04/filename2.jpg" />
[/wpvconditional]

You will replace room-size with the field slug from wp-admin, and replace the img srcs with full URLs. The 'filename1.jpg' in quotation marks at the end of the line should be replaced with whatever you have in the value of each checkbox.

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 vor 5 Jahren, 8 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von christianS-11 vor 5 Jahren, 8 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1219671

Hi,

I have a User Registration form with Checkboxes where can select images. (Label = img tag).
The values of each checkbox is the filename of the image (it needs to be translatable with wpml)

In the view I'd like to display the selected images but I am not sure how the get the separate values to build a img tag in the output.

Can you help me?

#1220076

Hi, there is no built-in way to loop over checkbox options in a View, but you can use the syntax from this article to write out some conditionals manually: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

[wpv-conditional if="( '[types field='room-size' option='0'][/types]' eq 'filename1.jpg' )"]
    <img src="/wp-content/uploads/2019/04/filename1.jpg" />
[/wpv-conditional]
  
[wpv-conditional if="( '[types field='room-size' option='1'][/types]' eq 'filename2.jpg' )"]
  <img src="/wp-content/uploads/2019/04/filename2.jpg" />
[/wpv-conditional]
  
[wpv-conditional if="( '[types field='room-size' option='2'][/types]' eq 'filename3.jpg' )"]
  <img src="/wp-content/uploads/2019/04/filename2.jpg" />
[/wpv-conditional]

...

You will replace room-size with the field slug from wp-admin, and replace the img srcs with full URLs. The 'filename1.jpg' in quotation marks at the end of the line should be replaced with whatever you have in the value of each checkbox.

#1220172

Hi,
thanks so far. In the meantime I put the complete img tag as option value (which seems to work) but your solution looks cleaner 😉