Support

Account

Home Forums Add-ons Gallery Field Populate post images in new gallery add-on Reply To: Populate post images in new gallery add-on

  • Yes thats exactly what I’ve done. I had an existing carousel that pulled images that were attached to the post. But once I implemented ACF gallery…my images stopped appearing in some posts, so I have the new script and the old script running together and I just check to see if the gallery field has images stored. I m also running WPML, that’s why i check for language..

    <?php
    // get the acf var depending on language using WPML
    $images = get_field( ( ICL_LANGUAGE_CODE==’fr’ ? ‘gallerie’ : ‘gallery’ ) );
    $src_str = ‘get_field’;
    $num_imgs = count($images);

    // Do we have images in the ACF Gallery ?
    if($num_imgs > 0 && is_array($images) ) {
    //
    } // no images in ACF gallery but we do have images attached to post
    else{
    $images = get_children( ‘post_type=attachment&post_mime_type=image&output=ARRAY_A&orderby=menu_order&order=ASC&post_parent=’.$post->ID);
    $src_str = ‘get_children’;
    }

    //if we have images enqueue the carousel scripts
    if( $images ):
    // Galleria Files
    wp_enqueue_script(‘galleria’);
    wp_enqueue_script(‘galleria-classic-js’);
    wp_enqueue_style(‘galleria-classic-css’);

    wp_enqueue_script(‘website-single’);

    wp_localize_script(
    ‘website-single’,
    ‘MyAjax’, array(” => ”,)
    );

    ?>

    <!– Display HTML –>
    <div id=”galleria”>
    <?php foreach( $images as $image ): ?>
    guid ); ?>” alt=”<?php echo ( $src_str == ‘get_field’ ? $image[‘alt’] : $image->post_title ); ?>” />
    <?php endforeach; ?>

    </div>

    <?php endif; ?>