Given this HTML code, how can I create a dynamic Carosuel with thumbnails using Bootstrap 4 that can be updated in back-end using ACF Repeater?
My Repeater field is called carousel_repeater and inside I have an Image field called carosuel_image
HTML code
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="custCarousel" class="carousel slide" data-ride="carousel" align="center">
<!-- slides -->
<div class="carousel-inner">
<div class="carousel-item active"> <img src="https://i.imgur.com/weXVL8M.jpg" alt="Hills"> </div>
<div class="carousel-item"> <img src="https://i.imgur.com/Rpxx6wU.jpg" alt="Hills"> </div>
<div class="carousel-item"> <img src="https://i.imgur.com/83fandJ.jpg" alt="Hills"> </div>
<div class="carousel-item"> <img src="https://i.imgur.com/JiQ9Ppv.jpg" alt="Hills"> </div>
</div> <!-- Left right --> <a class="carousel-control-prev" href="#custCarousel" data-slide="prev"> <span class="carousel-control-prev-icon"></span> </a> <a class="carousel-control-next" href="#custCarousel" data-slide="next"> <span class="carousel-control-next-icon"></span> </a> <!-- Thumbnails -->
<ol class="carousel-indicators list-inline">
<li class="list-inline-item active"> <a id="carousel-selector-0" class="selected" data-slide-to="0" data-target="#custCarousel"> <img src="https://i.imgur.com/weXVL8M.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-1" data-slide-to="1" data-target="#custCarousel"> <img src="https://i.imgur.com/Rpxx6wU.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="2" data-target="#custCarousel"> <img src="https://i.imgur.com/83fandJ.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="3" data-target="#custCarousel"> <img src="https://i.imgur.com/JiQ9Ppv.jpg" class="img-fluid"> </a> </li>
</ol>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="custCarousel" class="carousel slide" data-ride="carousel" align="center">
<div class="carousel-inner">
<?php
if( have_rows('carousel_repeater') ):
// Loop through rows.
while( have_rows('carousel_repeater') ) : the_row();
$sub_value = get_sub_field('sub_field');// whatever ur image field is called
?>
<div class="carousel-item active"> <img src="<?php echo $sub_value['url'] ?>g" alt="Hills"> </div>
<?php
// End loop.
endwhile;
?>
<ol class="carousel-indicators list-inline">
<li class="list-inline-item active"> <a id="carousel-selector-0" class="selected" data-slide-to="0" data-target="#custCarousel"> <img src="https://i.imgur.com/weXVL8M.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-1" data-slide-to="1" data-target="#custCarousel"> <img src="https://i.imgur.com/Rpxx6wU.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="2" data-target="#custCarousel"> <img src="https://i.imgur.com/83fandJ.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="3" data-target="#custCarousel"> <img src="https://i.imgur.com/JiQ9Ppv.jpg" class="img-fluid"> </a> </li>
</ol>
</div>
</div>
</div>
</div>
<?php
endif;
?>
Probs something like this, your gna need to play with it as i havent tested it but this is a start, would recommend you look into the documentation for ACF repeaters
https://www.advancedcustomfields.com/resources/repeater/
Related
Here is my Bootstrap ui that the data is fetched from the database. As you can see, the carousel is going down and cannot click next it just goes down. from the page.
1
please see the image above
data that I'm fetching are texts and not image
and here is my code
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<?php
$dataid;
$data = mysqli_query($con,"SELECT * FROM feedback");
$count = mysqli_num_rows($data);
if ($count != 0) {
echo '
<div class="row ">';
while($row = mysqli_fetch_array($data)) {
echo '
<!-- Wrapper for carousel items -->
<div class="carousel-inner">
<div class="item carousel-item active">
<p class="testimonial">'. $row['comment'] .'</p>
<p class="overview"><b>Anonymous</b></p>
<div class="star-rating">
<ul class="list-inline">
<li class="list-inline-item"><i class="fa fa-heart" ></i></li>
<li class="list-inline-item"><i class="fas fa-thumbtack" ></i></li>
<li class="list-inline-item"><i class="fas fa-archive"></i></li>
<li class="list-inline-item"><i class="fa fa-trash" ></i></li>
<li class="list-inline-item"><i class="fa fa-star-o"></i></li>
</ul>
</div>
</div>
</div>
';
}
}
?>
<!-- Carousel controls -->
<a class="carousel-control left carousel-control-prev" href="#myCarousel" data-slide="prev">
<i class="fa fa-angle-left"></i>
</a>
<a class="carousel-control right carousel-control-next" href="#myCarousel" data-slide="next">
<i class="fa fa-angle-right"></i>
</a>
</div>
</div>
The carousal structure is like
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Third slide">
</div>
</div>
</div>
so you need to repeat the carousel-item
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php while($row = mysqli_fetch_array($data)) { ?>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="First slide">
</div>
<?php } ?>
</div>
</div>
If you need to display the text in the Carousel that comes from database then just give some padding and background-color to the Image
<div class="carousel-item active">
<img src="<?php echo imageSrcFromDb; ?>" width="1100" height="500">
<div class="carousel-caption">
<h3><?php echo ; //Your Heading text ?></h3>
<p><?php echo ; //Some description ?></p>
</div>
</div>
<!-- Wrapper for carousel items -->
<div class="carousel-inner">
<?php
while($row = mysqli_fetch_array($data)) {
echo '
<div class="item carousel-item">
<p class="testimonial">'. $row['comment'] .'</p>
<p class="overview"><b>Anonymous</b></p>
<div class="star-rating">
<ul class="list-inline">
<li class="list-inline-item"><i class="fa fa-heart" ></i></li>
<li class="list-inline-item"><i class="fas fa-thumbtack" ></i></li>
<li class="list-inline-item"><i class="fas fa-archive"></i></li>
<li class="list-inline-item"><i class="fa fa-trash" ></i></li>
<li class="list-inline-item"><i class="fa fa-star-o"></i></li>
</ul>
</div>
</div>
';
}
?>
</div>
the while loop should be inside the class carousel-inner .
looking for a steer in the right direction getting this loop working. I'm nearly there but not 100% as I've got a mysterious box appearing at the top and the bottom of the search results. Would anyone be able to check over to see if the loop is right, please?
I've tried jigging the loop around but can't make any sense of it.
<?php get_header(); ?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<p class="text-muted text-size-small">
<?php
global $wp_query;
echo 'You have '.$wp_query->found_posts.' results found.';?>
</p>
<hr>
<?
php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="media-body">
<h6 class="media-heading text-semibold">
<?php echo get_post_meta(get_the_id(), 'title', true ); ?>,
<?php echo get_post_meta(get_the_id(), 'firstname', true ); ?>,
<?php echo get_post_meta(get_the_id(), 'lastname', true ); ?>
</h6>
<ul class="list-inline list-inline-separate text-muted mb-10">
<li><a href="#" class="text-muted">
<?php echo get_post_meta( get_the_id(), 'type', true ); ?>
</a> </li>
<li><?php echo get_post_meta(get_the_id(), 'netbios_name', true ); ?> |
<?php echo get_post_meta(get_the_id(), 'device_class', true ); ?></li>
</ul>
<?php echo get_post_meta( get_the_id(), 'asset_id', true ); ?>
<?php echo get_post_meta(get_the_id(), 'asset_status', true ); ?>
</div>
<div class="media-right text-nowrap">
<a href="<?php the_permalink();?>"
class="btn btn-warning">View</a>
</div>
</li>
<ul class="media-list content-group">
<li class="media panel panel-body stack-media-on-mobile">
<div class="media-left">
<a href="#">
<img src="assets/images/demo/brands/dell.png" class="img-rounded img-lg" alt="">
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_template_part('footer', 'simple');?>
<?php get_footer(); ?>
Here's what the HTML view is spitting out
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<p class="text-muted text-size-small">
You have 3 results found. </p>
<hr>
<div class="media-body">
<h6 class="media-heading text-
semibold">
, , </h6>
<ul class="list-inline list-inline-
separate text-muted mb-10">
<li><a href="#" class="text-
muted"> </a></li>
<li> | </li>
</ul>
</div>
<div class="media-right text-nowrap">
View
</div>
</li>
<ul class="media-list content-group">
<li class="media panel panel-body stack-
media-on-mobile">
<div class="media-left">
<a href="#">
<img src=" class="img-rounded
img-lg" alt="">
</a>
</div>
<div class="media-body">
<h6 class="media-heading text-
semibold">
34
, , </h6>
<ul class="list-inline list-inline-
separate text-muted mb-10">
<li><a href="#" class="text-
muted"> </a></li>
<li> | </li>
</ul>
</div>
<div class="media-right text-nowrap">
<a href="" class="btn btn-
warning">View</a>
</div>
</li>
<ul class="media-list content-group">
<li class="media panel panel-body stack-
media-on-mobile">
<div class="media-left">
<a href="#">
<img src=" class="img-rounded
img-lg" alt="">
</a>
</div>
<div class="media-body">
<h6 class="media-heading text-
semibold">
34
Mr, User, User </h6>
<ul class="list-inline list-inline-separate text-muted mb-10">
<li>User </li>
<li> | </li>
</ul>
</div>
<div
class="media-right text-nowrap">
View
</div>
</li>
<ul class="media-list content-group">
<li class="media
panel panel-body stack-media-on-mobile">
<div
class="media-left">
<a
href="#">
<img src=" class="img-rounded img-lg" alt="">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /main content -->
</div>
<!-- /page content -->
/div>
<!-- /page container -->
The below html just shows the images one by one down the page and not in a slideshow. I've put the images in the database giving each one their own column. Is this wrong? How can I make the images be a slideshow. Thanks for helping.
<div id="lodgeGallery" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#lodgeGalleryl" data-slide-to="0" class="active"></li>
<li data-target="#lodgeGalleryl" data-slide-to="1"></li>
<li data-target="#lodgeGalleryl" data-slide-to="2"></li>
<li data-target="#lodgeGalleryl" data-slide-to="3"></li>
<li data-target="#lodgeGalleryl" data-slide-to="4"></li>
<li data-target="#lodgeGalleryl" data-slide-to="5"></li>
<li data-target="#lodgeGalleryl" data-slide-to="6"></li>
<li data-target="#lodgeGalleryl" data-slide-to="7"></li>
<li data-target="#lodgeGalleryl" data-slide-to="8"></li>
<li data-target="#lodgeGalleryl" data-slide-to="9"></li>
<li data-target="#lodgeGalleryl" data-slide-to="10"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<?php
//<img src="img/img1.jpg" alt="">
echo "<img src='img/$galleryImg1'";
?>
</div>
<div class="item">
<?php
//<img src="img/img2.JPG" alt="">
echo "<img src='img/$galleryImg2'";
?>
</div>
<div class="item">
<?php
//<img src="img/img3.png" alt="">
echo "<img src='img/$galleryImg3'";
?>
</div>
<div class="item">
<?php
//<img src="img/img4.png" alt="">
echo "<img src='img/$galleryImg4'";
?>
</div>
<div class="item">
<?php
//<img src="img/img5.jpg" alt="">
echo "<img src='img/$galleryImg5' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img6.jpg" alt="">
echo "<img src='img/$galleryImg6' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img7.jpg" alt="">
echo "<img src='img/$galleryImg7' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img8.jpg" alt="">
echo "<img src='img/$galleryImg8'";
?>
</div>
<div class="item">
<?php
//<img src="img/img9.jpg" alt="">
echo "<img src='img/$galleryImg9' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img10.JPG" alt="">
echo "<img src='img/$galleryImg10' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img11.jpg" alt="">
echo "<img src='img/$galleryImg11' ";
?>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#lodgeGallery" role="button" data- slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#lodgeGallery" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
Seeing your code, i think you have ne error in the syntax of how you echo the image from server.
It should be
"<img src ='img/'.$galleryImg1.'"
For pulling the images from a database:
2 columns: RowID & ImageURL
select RowID, Image URL from db
$sql = ("SELECT RowID,ImageURL FROM db.dbo.table");
$res = odbc_exec($dbConn,$sql);
while ($images = odbc_fetch_array($res)){
echo "<img src="img/".$images."'/>";
}
I am not able to show images in slider one by one, it displays all images at once. My static code is here and it works well with sliding images.
<section id="main-slider" class="no-margin" data-ride="carousel">
<div class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#main-slider" data-slide-to="0" class="active"></li>
<li data-target="#main-slider" data-slide-to="1"></li>
<li data-target="#main-slider" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="item active" style="background-image: url(users/assets/images/New/4.jpg)">
<div class="container">
<div class="row slide-margin">
<div class="col-sm-12">
<div class="media services-wrap wow fadeInDown">
<div class="pull-left">
<img class="img-responsive" src="images/services/services1.png">
</div>
<div class="media-body">
<h3 class="media-heading">SEO Marketing</h3>
<p>Lorem ipsum dolor sit ame consectetur adipisicing elit</p>
</div>
</div>
</div>
</div>
</div>
</div><!--/.item-->
</div><!--/.carousel-inner-->
</div><!--/.carousel-->
<a class="prev hidden-xs" href="#main-slider" data-slide="prev">
<i class="fa fa-chevron-left"></i>
</a>
<a class="next hidden-xs" href="#main-slider" data-slide="next">
<i class="fa fa-chevron-right"></i>
</a>
</section><!--/#main-slider-->
When i made it dynamic it is not sliding images, but displaying all images from database
<section id="main-slider" class="no-margin" data-ride="carousel">
<div class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#main-slider" data-slide-to="0" class="active"></li>
<li data-target="#main-slider" data-slide-to="1"></li>
<li data-target="#main-slider" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="item active" style="background-image: url(users/assets/images/New/4.jpg)">
<div class="container">
<div class="row slide-margin">
<div class="col-md-12">
<div class="media services-wrap wow fadeInDown">
#foreach($data as $data)
<img src="{{asset($data->image)}}">
<h4>{{ $data->text}}</h4>
#endforeach
</div>
</div>
</div>
</div>
</div><!--/.item-->
</div><!--/.carousel-inner-->
</div><!--/.carousel-->
<a class="prev hidden-xs" href="#main-slider" data-slide="prev">
<i class="fa fa-chevron-left"></i>
</a>
<a class="next hidden-xs" href="#main-slider" data-slide="next">
<i class="fa fa-chevron-right"></i>
</a>
How can i slide image one by one
Try put this div in Foreach loop '<div class="item"></div>'.
As It seems .item class will work as each slide.
Check this link for example..
http://jsfiddle.net/WmMXa/3/
Hope it helps
Put the foreach before your carousel-item and add this code class = $loop->first ? 'active' : '' that will put only the first photo as active as your static code does.
#foreach( $photos as $photo )
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img class="d-block img-fluid" src="{{ $photo->image }}" alt="{{ $photo->title }}">
<div class="carousel-caption d-none d-md-block">
<h3>{{ $photo->title }}</h3>
<p>{{ $photo->descriptoin }}</p>
</div>
</div>
#endforeach`
Hopefully, it will work for you.
I have the following site,
http://bamboobeez.com/
how could i display 5 images instead of 3?
I cant seem to get the below code right?
<div id="slider-fixed-products" class="carousel slide">
<div class="carousel-inner">
<div class="active item">
<ul class="thumbnails">
<?$i=0;
foreach ($ads as $ad):?>
<?if ($i%3==0 AND $i!=3):?></ul></div><div class="item"><ul class="thumbnails"><?endif?>
<li class="span3">
<div class="thumbnail">
<a href="<?=Route::url('ad', array('category'=>$ad->category->seoname,'seotitle'=>$ad->seotitle))?>">
<?if($ad->get_first_image()!== NULL):?>
<img src="<?=URL::base('http')?><?=$ad->get_first_image()?>" >
<?else:?>
<img src="http://www.placehold.it/200x200&text=<?=$ad->category->name?>">
<?endif?>
</a>
<div class="caption">
<h5><?=$ad->title?></h5>
<p><?=substr(Text::removebbcode($ad->description), 0, 30)?></p>
</div>
</div>
</li>
<?$i++;
endforeach?>
</ul>
</div>
</div>
<a class="left carousel-control" href="#slider-fixed-products" data-slide="prev">‹</a>
<a class="right carousel-control" href="#slider-fixed-products" data-slide="next">›</a>
</div>
<?if ($i%5==0 AND $i!=5):?></ul></div><div class="item"><ul class="thumbnails">
in if condition use 5 instead of 3