Home Forums Front-end Issues Display images from url in Text field


Display images from url in Text field

  • I am building a Carousel that displays images that are loaded on a separate folder on the server and not into the WP Media gallery.

    The images are store in ACF in a Text filed, something like

    How can I display the images in the carousel, using my code? What I get at the moment s nothing, just a Carousel without images

        		//code to display the banners
        		//check that the page has banners
    			if( have_rows('images') ): 
            //count the number of banners
            $count = count(get_field('images'));?>
            <div id="banner-carousel" class="carousel slide" data-ride="carousel">
            //add the indicators only if there is more than one banner
            if ($count > 1) {?>
               <?php $i=0; ?>
                <?php while ($i < $count) { ?>
                    <li data-target="#banner-carousel" data-slide-to="<?php echo $i; ?>" class="<?php if ($i == 0) {echo'active';} ?>"></li>
                <?php $i++; } ?>
            <?php } ?>
            <?php //loop through all the banners ?>
            <?php $i=0; ?>
                <div class="carousel-inner">
            <?php while( have_rows('images') ): the_row(); 
                //get the banner variables. 
                $images = get_sub_field('image');            
    			<div style="background: url('<?php echo $image['url']; ?>') no-repeat center center; background-size: cover;" class="carousel-item <?php if ($i == 0) {echo'active';} ?>">
                    <div class="container">
                        <div class="row carousel-mieten">
                <?php $i++; ?>
            <?php endwhile; ?>
               <?php if ($count > 1) {?>
                <a href="#banner-carousel">
                    <span class="carousel-control-prev-icon" aria-hidden="true"></span>   
                <a href="#banner-carousel">
                    <span class="carousel-control-next-icon" aria-hidden="true"></span>    
                <?php } ?>
    <?php endif; 
  • Not sure if this will cause your issue, but the first think to change is that you need to get the repeater before you use have_rows().

    $images = get_field('images');
    if (!empty($images)) {
      $count = count($images);
    if (have_row('images')) {
       // your code continues

    The next issue is that you are attempting to use a text field like an image field. A text field only returns the value entered into it

    $image = get_sub_field('image');
    ..... background: url('<?php echo $image; ?>') ...
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.