Custom Fields
Re-Envisioned
Support General One random image from an Image Advanced field in Oxygen

  • Creator
    Topic
  • #29468
    Ilan
    Participant

    I'm trying to accomplish exactly what this guy is doing here

    but using metabox instead of ACF.
    He is using this snippet
    https://www.paulchinmoy.com/display-random-image-acf-gallery-oxygen-builder/

    I'm sure a view with Twig is probably the right direction, but I'm not sure. Do you have any suggestions?
    The other factor is the field is saved in a Settings page, not at the post level, if that matters.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #29478
    Long Nguyen
    Moderator

    Hi ilan,

    Thank you for reaching out.

    Meta Box has the same way to create image_advanced field and get its value. You can get more details on the documentation
    https://docs.metabox.io/fields/image-advanced/
    https://docs.metabox.io/extensions/mb-settings-page/

    Paul uses the PHP code to create the snippet so I think you should also use PHP code to understand how it works.

    #29483
    Ilan
    Participant

    Ya it looks like this one is above my head. I'll have to hope someone makes a video tutorial for me one day 🙂

    #29577
    Ilan
    Participant

    Ya I'm totally lost here - can you help me out please? What changes would I make to the snippet to have it work with metabox and pulling images from the settings page fields?

    #29578
    Ilan
    Participant

    I think I'm getting closer - using MB Views I'm trying to output a random item from the array.

    {% set group = attribute( site, 'practice-specific-images' ) %}
    {% set item = random(group) %}
        <img src="{{ item.full.url }}" width="100%" height="auto" alt=""> 
     

    unfortunately this is not giving me anything on the front end, viewing the source give me "unknown" for the URL.
    Saved as a shortcode for easy use in Oxygen.
    I feel like i'm so close here - any suggestions you can offer?

    #29580
    Ilan
    Participant

    FINALLY GOT IT!

    For the next person with this problem, i got there in the end using views, just forgot to add the field name to the random function

    {% set group = attribute( site, 'practice-specific-images' ) %}
    {% set item = random(group.gallery) %}
        <img src="{{ item.full.url }}" width="100%" height="auto" alt=""> 

    `

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