Hi @alfaomega,
Thanks for bringing this up.
Maybe this isn’t what you had in mind.
But how about:
Fields
Multi-select, with these options:
Foo
Bar
Baz
Example
Image Field 1
Image Field 2
PHP Template
If the multi-select value is Foo or Bar, display Image Field 1
If the multi-select value is Baz or Example, display Image Field 2
Hi Ryan,
Thanks for your super fast reply.
That is exactly what I need:
If the multi-select value is Foo, display Image 1
If the multi-select value is Bar, display Image 2
The challenge I’m having is setting it up in the PHP as it conflicts with the return values.
can you please advise what will be the correct line of code for his?
Many Thanks
Hi @alfaomega,
Good to hear!
Hm, if there is a multi-select field named foo-multiselect, then maybe:
$text = block_value( 'foo-multiselect' );
if ( in_array( 'Foo', $text, true ) ) { // If the multiselect has 'Foo' selected
block_field( 'image-field-1' );
}
block_value() gets the value, while block_field() echoes the value
Hi Ryan,
Thanks a lot for your answer.
Is there also an option to display a pre-defined image file from a url – (www.google.com/image.jpg), instead of a field?
My apologies for bothering you, but I’m a novice and still learning a lot about PHP.
Many Thanks
Hi @alfaomega,
No problem, I’m glad you’re using Block Lab π
Sure, you could hard-code that in the template, or add it via a URL field:
https://getblocklab.com/docs/fields/url/
Thank You Ryan,
This is my best plugin so far. It saved me a ton of manual work and editing.
Keep up the great work
Thanks, that made my day!