is it possible to make a carousel with passed parameters? what i am trying to do is dynamically create a carousel from the items passed to it.
the code is smarty php code that is passing text into the bootstrap code. below is the smarty code.
{iterate from=news item=item}
{$item->getSubject()}
{$item->getIntroText()}
{$item->getText()}
{/iterate}
my bootstrap code is below. I tried playing around with the placement of the smarty iterate code in different places, but I keep getting one large container with multiple carousel items one below the other. what i really want to do is get one container that displays one carousel item and then users can click the carousel navigation links to cycle through all items.
any advice or help appreciated.
{iterate from=news item=item}
<div class="container news-carousel">
<!-- cont 1 -->
<div class="row w-100">
<!-- row -->
<div class="col">
<div id="carousel" class="carousel slide" data-ride="carousel">
<!-- start carousel -->
<ol class="carousel-indicators"> <!-- this this deteminse the little items below not sure we need them-->
<li data-target="#carousel" data-slide-to="0" class="active"></li>
</ol>
<div class="carousel-inner rounded">
<div class="carousel-item active">
<div class="row w-100 p-0 m-0">
<div class="col p-2 m-3 ">
<h5 class="font-weight-bold" >{$item->getSubject()}</h5>
<p class="m-2 p-2" >{$item->getIntroText()}</p>
{if $item->getText()}
<a class="text-info text-capitalise p-1" href="{url page="index" op="newsDetails" path=$item->getNewsId()}">
read more
</a>
{/if}
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div> <!-- close carousel inner -->
</div> <!-- carousel close -->
</div>
</div>
</div><!-- cont 1 -->
{/iterate}
revised code
...
<!-- we make a new bloc -->
{iterate from=news item=item}
<div class="container">
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<p>{$item->getSubject()}</p>
<p>{$item->getIntroText()}</p>
{if $item->getText()}
Read more
{/if}
</div>
</div>
</div>
</div>
{/iterate}
...
Related
Hi guys im using WP advanced custom fields pro repeater function, trying get my bootstrap slider to work with advanced custom fields.
here is my ACF set up
ACF setup WP side
and here is my bootsrap code with ACF integrated.
my code
<section class="pb-5">
<div class="container">
<div id="carousel_03" class="carousel slide" data-ride="carousel">
<div class="row">
<div class="col-lg-4">
<ol class="carousel-indicators tabs row">
<li class="col-lg-12 col-sm-6 mb-2 active">
<div data-target="#carousel_03" data-slide-to="0" role="button" class="carousel-indicator p-3">
<h4 class="mb-1">one</h4>
</div>
</li>
<li class="col-lg-12 col-sm-6 mb-2">
<div data-target="#carousel_03" data-slide-to="1" role="button" class="carousel-indicator p-3">
<h4 class="mb-1">two</h4>
</div>
</li>
<li class="col-lg-12 col-sm-6 mb-2">
<div data-target="#carousel_03" data-slide-to="2" role="button" class="carousel-indicator p-3">
<h4 class="mb-1">three</h4>
</div>
</li>
<li class="col-lg-12 col-sm-6 mb-2">
<div data-target="#carousel_03" data-slide-to="3" role="button" class="carousel-indicator p-3">
<?php
if( have_rows('slider') ):
while ( have_rows('slider') ) : the_row();
the_sub_field( 'title');
?>
<h4 class="mb-1"><?php the_sub_field($section . 'title') ?></h4>
<?php
endwhile;
endif;
?>
</div>
</li>
</ol>
</div>
<div class="col-lg-8 mb-3">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="some.svg" class="d-block w-100" alt="alt">
</div>
<div class="carousel-item">
<img src="some.svg" class="d-block w-100" alt="alt">
</div>
<div class="carousel-item">
<img src="some.svg" class="d-block w-100" alt="alt">
</div>
<div class="carousel-item">
<?php
if( have_rows('slider') ):
while ( have_rows('slider') ) : the_row();
the_sub_field( 'image');
?>
<img class="img-fluid"
src="<?php the_sub_field($section . 'image') ?>"
alt="<?php the_sub_field($section . 'alt') ?>">
<?php
endwhile;
endif;
?>
</div>
</div>
<a class="carousel-control-prev" href="#carousel_03" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
<a class="carousel-control-next" href="#carousel_03" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
</div>
</div>
</div>
</div>
</section>
My aim
for less code and to have ACF to pull all images for the slider in the correct order.
My problem
as I currently do not have my images in a array they all display where I cal my sub field, whats the best solution to get this working correctly ?
You are better off using get_field() (https://www.advancedcustomfields.com/resources/get_field/) to retrieve the repeater values in this instance, as this returns an associative array containing all sub-field values.
You can then iterate that array to output the HTML you need for the Bootstrap carousel.
Also worth noting that the image values returned will also contain a key sizes with URLs to the images of all of your themes thumbnail sizes in it, if you want to output a particular image size in the carousel.
Note: I haven't actually tested this with Bootstrap, but it should work.
<?php
// get the ACF values using get_field()
$sliderImages = get_field('slider');
?>
<section class="pb-5">
<div class="container">
<div id="carousel_03" class="carousel slide" data-ride="carousel">
<div class="row">
<div class="col-lg-4">
<ol class="carousel-indicators tabs row">
<!-- Iterate images to output indicators -->
<?php foreach ($sliderImages as $imgNumber => $image) : ?>
<li class="col-lg-12 col-sm-6 mb-2<?php if ($imgNumber === 0) : ?> active<?php endif ?>">
<div data-target="#carousel_<?= $imgNumber ?>" data-slide-to="<?= $imgNumber ?>" role="button" class="carousel-indicator p-3">
<h4 class="mb-1"><?= $imgNumber + 1 ?></h4>
</div>
</li>
<?php endforeach ?>
</ol>
</div>
<div class="col-lg-8 mb-3">
<div class="carousel-inner">
<!-- Iterate images again to output carousel items -->
<?php foreach ($sliderImages as $imgNumber => $image) : ?>
<div class="carousel-item<?php if ($imgNumber === 0) : ?> active<?php endif ?>">
<img src="<?= $image['image']['url'] ?>" alt="<?= $image['image']['alt'] ?>">
</div>
<?php endforeach ?>
</div>
<a class="carousel-control-prev" href="#carousel_03" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
<a class="carousel-control-next" href="#carousel_03" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
</div>
</div>
</div>
</div>
</section>
I have a slider built in bootstrap and using Advanced Custom Fields in WordPress, my data attribute when written in HTMl the data-slide-to="" would be 0, 1 ,2 ,3 and so on.
If i was to write this in HTML it works. now I have integrated it with WordPress Advanced Custom Fields and added php I can now inspect the code and see the data attribute having 0, 1, 2, 3 onward. however now i click on the div with this attribute and the slide wont change as it did written in HTML.
is there something in my code preventing this, why wont my slide change now if click on the div with a different data-slide-to=""?
For example in HTML if i click on the div with data-slide-to="1" then it shows the second slide.
however now written in PHP this in not working, can some one help me understand why?
my code
<?php
$sliderImages = get_field('slider');
$count = 0;
?>
<section class="pb-5">
<div class="container">
<div id="carousel_03" class="carousel slide" data-ride="carousel">
<div class="row">
<div class="col-lg-4">
<ol class="carousel-indicators tabs row">
<?php if (have_rows('slider')):
while (have_rows('slider')): the_row();
?>
<li class="col-lg-12 col-sm-6 mb-2 <?php echo ($count ++) >= 1 ? '' : 'active'; ?> ">
<div data-target="#carousel_3" data-slide-to="<?php echo ($count ++); ?>" role="button"
class="carousel-indicator p-3">
<h4 class="mb-1"><?php the_sub_field('title', $post->ID)?></h4>
<?php
endwhile;
endif;
?>
</div>
</li>
</ol>
</div>
<div class="col-lg-8 mb-3">
<div class="carousel-inner">
<?php foreach ($sliderImages as $imgNumber => $image) : ?>
<div class="carousel-item<?php if ($imgNumber === 0) : ?> active<?php endif ?>">
<img src="<?= $image['image']['url'] ?>" alt="<?= $image['image']['alt'] ?>">
</div>
<?php endforeach ?>
</div>
<a class="carousel-control-prev" href="#carousel_03" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
<a class="carousel-control-next" href="#carousel_03" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
</div>
</div>
</div>
</div>
</section>
I create more than one slider dynamically using php but prev or next button is working only in first slider and not in rest slider due to having same class in control, other ones are not working. Please help me to fix this.
here is my slider code with php
if($counter == 0)
{
//$image_path='<div class="panel-body" style="background-image: url('.$rowu['event_image'].');>';
$Indicators ='<li data-target="#carousel-example-generic" data-slide-to="'.$counter.'" class="active"></li>';
$slides = '<div class="item active" >
<div class="container-fluid" style="marign:0px;padding:0px; background-image: url('.$rowu['event_image'].');">
<div class="highlighted">'.$event_category.'</div>
<div class="highlighted">'.$event_city.'</div>
<div class="highlighted">'.date_format($startDate,'d F').'</div>
<div class="pull-right" style="margin-top:270px">
Book
</div>
</div>
</div>';
}
else{
//$image_path .='<div class="panel-body" style="background-image: url('.$rowu['event_image'].');>';
$Indicators .='<li data-target="#carousel-example-generic" data-slide-to="'.$counter.'"></li>';
$slides .= '<div class="item">
<div class="container-fluid" style="marign:0px;padding:0px; background-image: url('.$rowu['event_image'].');">
<div class="highlighted">'.$event_category.'</div>
<div class="highlighted">'.$event_city.'</div>
<div class="highlighted">'.date_format($startDate,'d F').'</div>
<div class="pull-right" style="margin-top:270px">
Book
</div>
</div>
</div>';
}
$counter++;
}
echo '
<div class="panel panel-default" style="font-family: Futura,Trebuchet MS,Arial,sans-serif;">
<!-- panel body where slider will work -->
<div class="panel-body">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
'.$Indicators.'
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
'.$slides.'
</div>
<!-- Controls -->
<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>
`
each slider should have a unique ID
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
as you see it controls #carousel-example-generic
Also it's same for bullets
<li data-target="#carousel-example-generic" data-slide-to="'.$counter.'"></li>
data-target define the slider.
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 am making a dynamic slider with laravel. I need to slide content and image that are in database. Everything is well but I have a gap(white space) between the slides. The first image slides with content, second is blank and after sometime third image slides and after third image there is blank page slide.
I have two images in database and in folder. The image should slides frequently one after another but this is not happening.
I may have a mistake in my if else statement.
my html code for slider is like this,it works well
<section>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<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>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<div class="bnr-img">
<img src="css/images/banner.jpg" alt="..." style="width:100%;">
<div class="carousel-caption">
Group com Family Hospitalization<br> Insurance
</div>
</div>
<h1>"We will be there when you need us most"</h1>
</div>
<div class="item">
<div class="bnr-img">
<img src="css/images/bnr-medi.jpg" alt="..." style="width:100%;">
<div class="carousel-caption">
Health Insurance
</div>
</div>
<h1>"Securing Your Health"</h1>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control arw1" href="#carousel-example-generic" role="button" data-slide="prev">
<img src="css/images/arw-left.png" class="img-responsive">
</a>
<a class="right carousel-control arw1" href="#carousel-example-generic" role="button" data-slide="next">
<img src="css/images/arw-right.png" class="img-responsive">
</a>
</div>
</section><!--Slider end-->
my code for dynamic slider is like this:
<h2>services</h2>
<div id="carousel-example-generic1" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner inner" role="listbox">
#if(isset($services))
#foreach($services as $service)
<div class="item active">
</div>
<div class="item">
<div class="col-md-4">
<img src="frontend/services/{{$service->image}}">
</div>
<div class="col-md-8">
<p>
<span class="hilights2">{{$service->title}}</span><br>
{{$service->description}}
Read More
</p>
</div>
</div>
#endforeach
#endif
</div>
<!-- Controls -->
Most likely you have some unwanted margin on one of your elements. Try right clicking and hitting inspect element to see which element is taking up the whitespace, and then using css to set margin:0;
I have had the same problem,
when i figured the solution it was I've css file with code
.next,.prev{
display: none !important;
}
Regards