Reputation: 1929
I'm using ACF plugin and i create a flexible content to show title, content and gallery but i can't get the images.
My code is this:
<div id="services-pages">
<?php
if( have_rows('serviços') ):
while ( have_rows('serviços') ) : the_row();
?>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="content">
<div class="title">
<hr>
<span><?php echo the_sub_field('title');?></span>
</div>
<div class="info">
<p><?php echo the_sub_field('content');?></p>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="row images">
<?php
$images = the_sub_field('images');
var_dump($images);
?>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="slider-service-element">
<?php foreach( $images as $image ): ?>
<div>
<img src="<?php echo $image['url']; ?>" />
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="slider-service-main">
<?php foreach( $images as $image ): ?>
<div>
<img src="<?php echo $image['url']; ?>" />
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
endwhile;
else :
?>
<div>
<span>no records</span>
</div>
<?php
endif;
?>
</div>
I already try to get gallery with get_field()
and the_sub_field()
.
How can i solve that?
Thank you.
Upvotes: 0
Views: 2534
Reputation: 1
<?php if( have_rows('glp_images') ):
// loop through the rows of data
while ( have_rows('glp_images') ) : the_row();
$images = get_sub_field('glp_img');
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<div>
<img src="<?php echo $image; ?>" alt="" />
</div>
<?php endforeach; endif;?>
<?php endwhile; endif; ?>
Upvotes: 0
Reputation: 589
Try something like this
$images = get_sub_field('images');
if( $images ):
foreach( $images as $image ):
?><img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /><?php
endforeach;
endif;
There's a post on acf forum about it
https://support.advancedcustomfields.com/forums/topic/gallery-field-within-a-repeater-field/
Upvotes: 1