简体   繁体   中英

ACF Repeater in Wordpress not showing images

I'm having trouble getting images shown with a repeater in Wordpress. For some reason it only shows the alt text instead of the image itself? example

the upper images are my thumbnail posts and are showing correctly. Does anyone know whats causing this?

my code

   <div class="row">
    <div class="col-sm-6 left"><h1>COMMERCIAL</h1><br>
       <div class="page-header">

        <?php $mymovies = new WP_Query(array(
          'post_type' => 'my_movies'
          )); ?>

          <?php while($mymovies->have_posts()) : $mymovies->the_post(); ?>
            <div class="movie-colums">
             <div class="thumbtitle group">
                <div class="preview">
                   <?php the_post_thumbnail('thumbnail'); ?>
                   <h1><?php the_title(); ?><br>
                      <?php the_field('year'); ?>   
                      <?php
                      // check if the repeater field has rows of data
                      if( have_rows('images_rep') ):
                        // loop through the rows of data
                        while ( have_rows('images_rep') ) : the_row();
                    // display a sub field value
                    the_sub_field('image');
                    endwhile;
                    else :
                       // no rows found
                        endif;
                    ?>                                  
                </h1>
            </div>

        </div>
    </div>
 <?php endwhile; ?>
</div>

thanks in advance

Your PHP bit for the repeater stuff should be:

<?php if( have_rows('images_rep') ): ?>

    <?php while( have_rows('images_rep') ): the_row(); 
        $image = get_sub_field('image');
    ?>

        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>">

    <?php endwhile; ?>

<?php endif; ?>

It looks like your example is outputting the image object so just wrap the image URL in an image tag.

Ref: https://www.advancedcustomfields.com/resources/image/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM