Support

Account

Home Forums Front-end Issues Images dont pass through my For-loop.

Solved

Images dont pass through my For-loop.

  • Hello there, hope everyone is well.

    I will just cut the chase. I’ve had a look all over the internet for a solution but no luck.

    The problem is that I tried to do a for loop but it will skip the row with images. However, images do show up if I use a while loop.

    I had inspected the site elements, it showed that the images do pass through too.

    Any help on this would be greatly appreciated as I am completely lost.

    <div class="contact-content">
    
    			<table>
    				<tr>
    					<?php $rows=get_field('contact_fields'); if($rows) { foreach ($rows as $row) { ?>                   
    				<td>
                         <div class="contact-method">
    					 
    						<?php echo $row['lol']; ?>
    					 </div>
                    </td>
    				
                    <td>
                        <div class="contact-image" style="background-image: url(<?php echo $row['image']; ?>);"></div>
    				</td>
    				
    				<td>
                         <div class="contact-method">
    					 
    						<?php echo $row['contact_method']; ?>
    					 </div>
                    </td>			
    					<?php } } ?>
    				</tr>
                </table>
    			
    			</div>

    *note: the sub_field(‘lol’) is just to test the loop by putting before and after the sub_field(‘image’).

  • Hi @claya

    Might it be that your image field returns an image array rather than just the image url? This can be set on the image field settings

    In that case you’d do:

    
    <div class="contact-image" style="background-image: url(<?php echo $row['image']['url']; ?>);"></div>
    
  • Hi @jonathan

    I had selected “Image URL” in Return Value at my image repeater.

    I tried your method, but no image output is being echoed.
    It showed this in the site elements:

    <div class="contact-image" style="background-image: url(<br />
    <b>Warning</b>:  Illegal string offset 'url' in <b>C:\xampp\htdocs\highheels\wp-content\themes\naked-wordpress-master\page-contact.php</b> on line <b>28</b><br />
    h);"></div>
  • Yeah if you’ve set it to image URL then my code would not work 🙂 It’s based on image object. Could you try switching the image return setting to object and use my code?

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Images dont pass through my For-loop.’ is closed to new replies.