Loop custom field images
-
Ok here is my current code:
$image = get_field('topimg'); $link = get_field('link', $image['id']); ?> <div class="images"> <section id="topIMG"> <img src="<?php echo $image['url']; ?>" /> </section> </div>
You can see what I’m doing. But I have more <section>s i want to add such as “leftIMG”, “centerIMG”, and “rightIMG”. I was trying to create a foreach loop where I would put the fields in an array (as you can see get_field(‘topimg’) is a field) so I can get each image to be displayed. Hopefully you understand what Im trying to do.
This is what I tried to do:
<?php $array = array('topimg', 'leftimg', 'centerimg', 'rightimg'); $image = get_field($array); $link = get_field('link', $image['id']); $output = '<div class="images">'; foreach($image as $image) { $output .= '<section id='.$array.'>'; $output .= '<img src='.$image['url']'>'; $output .= '</section>'; } $output .= '</div>'; echo $output; ?>
but it doesn’t work and I get errors. Can some help me out at all?
- The topic ‘Loop custom field images’ is closed to new replies.