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.
Related
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/
I'm using PHP's "include" function to display static elements on all my pages, but the end result is not displaying as it should.
index code:
<?php
require '../../views/sidebar.php';
require '../../views/navbar.php';
?>
<div class="card">
<div class="card-header">
Test
</div>
<div class="card-body">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
sidebar code:
<nav class="side-navbar">
<div class="side-navbar-wrapper">
<div class="sidenav-header d-flex align-items-center justify-content-center">
<div class="sidenav-header-inner text-center"><img src="../../views/img/logo.jpg" alt="menulogo" class="img-fluid rounded-circle">
<h2 class="h5">Test</h2><span>Dashboard</span>
</div>
<div class="sidenav-header-logo"> <strong>B</strong><strong class="text-primary">D</strong></div>
</div>
<div class="main-menu">
<h5 class="sidenav-heading">Main</h5>
<ul id="side-main-menu" class="side-menu list-unstyled">
<li> <i class="icon-home"></i>Home </li>
<li> <i class="icon-form"></i>Forms </li>
<li> <i class="fa fa-bar-chart"></i>Charts </li>
<li> <i class="icon-grid"></i>Tables </li>
<li> <i class="icon-interface-windows"></i>Example dropdown
<ul id="exampledropdownDropdown" class="collapse list-unstyled ">
<li>Page</li>
<li>Page</li>
<li>Page</li>
</ul>
</li>
<li> <i class="icon-interface-windows"></i>Login page</li>
<li> <a href="#"> <i class="icon-mail"></i>Demo
<div class="badge badge-warning">6 New</div></a></li>
</ul>
</div>
<div class="admin-menu">
<h5 class="sidenav-heading">Second menu</h5>
<ul id="side-admin-menu" class="side-menu list-unstyled">
<li> <i class="icon-screen"> </i>Demo</li>
<li> <a href="#"> <i class="icon-flask"> </i>Demo
<div class="badge badge-info">Special</div></a></li>
<li> <i class="icon-flask"> </i>Demo</li>
<li> <i class="icon-picture"> </i>Demo</li>
</ul>
</div>
</div>
</nav>
this is a snippet from a bootstrapious template I'm using for learning purposes, and the css is both bootstrap and the template's, untouched.
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 .
I've used Bootstrap carousel in my webpage but there is a problem in the slides. The first image slides with content, second is blank, then third image slides, then third image there is blank page slide.
My code:
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" ></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2" class="active"></li>
</ol>
<div class="carousel-inner">
<div class="item">
<img src="/site/img/daa.jpg" >
</div>
<div class="item">
<img src="/site/img/2.jpg" >
</div>
<div class="item active">
<img src="/site/img/grad.jpg" >
</div>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>
</div>
No margins, no padding, no .left or .right , and finally no spaces in the code..
What could the problem be?
Your code has some issues im edited your code Look at new updated and now you can understand Bootstrap Carousel Plugin
The Carousel plugin is a component for cycling through elements, like a carousel (slideshow).
Learn more about it W3SCHOOL
<div id="myCarousel" class="carousel slide" data-ride="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>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="first-slide" src="http://s32.postimg.org/osirordf9/2_black_wallpaper_pattern_preview.jpg" alt="First slide">
<div class="container">
</div>
</div>
<div class="item">
<img class="second-slide" src="http://s32.postimg.org/osirordf9/2_black_wallpaper_pattern_preview.jpg" alt="Second slide">
<div class="container">
</div>
</div>
<div class="item">
<img class="third-slide" src="http://s32.postimg.org/osirordf9/2_black_wallpaper_pattern_preview.jpg" alt="Third slide">
<div class="container">
</div>
</div>
</div>
<a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class
Thanks for your interest. I've used fiddle and tested my carousel, it worked fine there,
so after more effort, I detected the problem. It was because I have css file with
.next,.prev{
display: none !important;
}
but I don't understand deeply why it causes blank slide, not only white sides in my slides!
thanks again
I want to show on a carousel/slider the photos related to the last 3 posts that have been made on my page.
The $last3 variable gets the last three posts:
<div class="row carousel-holder">
<div class="col-md-12">
<div id="carousel-example-generic" class="product carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
#foreach($last3 as $post)
<div class="item active">
<div class="fill" style="background-image:url('../../images/Blog/{{$post->photo}}');"></div>
<h2>{{$post->title}}</h2>
</div>
#endforeach
</div>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>