Home › Forums › Front-end Issues › 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 https://www.domain.com/assetts/images/image-1.jpg
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
<?php
//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">
<?php
//add the indicators only if there is more than one banner
if ($count > 1) {?>
<ol>
<?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++; } ?>
</ol>
<?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">
</div>
</div>
</div>
<?php $i++; ?>
<?php endwhile; ?>
</div>
<?php if ($count > 1) {?>
<a href="#banner-carousel">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
</a>
<a href="#banner-carousel">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
</a>
<?php } ?>
</div>
<?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; ?>') ...
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.