Support » Plugin: Block Lab » Return pre-defined image

  • Resolved AlfaOmega

    (@alfaomega)


    Hey All 🙂
    I’m trying to use Block Lab to display images instead of a text value. Can someone please advise what would be the best way to go here. Ex if a use a multi-select and select a couple of text values I want a pre-defined image to be displayed in the front end?
    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Ryan Kienstra

    (@ryankienstra)

    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

    AlfaOmega

    (@alfaomega)

    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

    Plugin Author Ryan Kienstra

    (@ryankienstra)

    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' );
    }
    
    Plugin Author Ryan Kienstra

    (@ryankienstra)

    block_value() gets the value, while block_field() echoes the value

    AlfaOmega

    (@alfaomega)

    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

    Plugin Author Ryan Kienstra

    (@ryankienstra)

    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/

    AlfaOmega

    (@alfaomega)

    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

    Plugin Author Ryan Kienstra

    (@ryankienstra)

    Thanks, that made my day!

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.