Bug in carousel slider encoder
I'm new to codeigniter, I don't know how to display carousel slider in codeigniter
<div class="contact-form">
<div class="carousel slide" id="fade-quote-carousel" data-ride="carousel" data-interval="3000">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-target="#fade-quote-carousel" data-slide-to="0" class="active"></li>
<li data-target="#fade-quote-carousel" data-slide-to="1"></li>
<li data-target="#fade-quote-carousel" data-slide-to="2" ></li>
<li data-target="#fade-quote-carousel" data-slide-to="3"></li>
<li data-target="#fade-quote-carousel" data-slide-to="4"></li>
<li data-target="#fade-quote-carousel" data-slide-to="5"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<?php
foreach($testimonials as $t)
{
?>
<?php
?>
<div class="active item">
<div class="profile-circle" style="background-color: rgba(0,0,0,.2);">
<img class="profile-circle" src="<?php echo base_url(); ?>uploads/images/testimonials/<?php echo $t->picture; ?>" alt="testimonials_image">
</div>
<blockquote>
<p><?php echo $t->content; ?></p>
</blockquote>
</div>
<?php
}
?>
</div>
</div>
</div>
this is the code, in fact i know what the error is, but i dont know how to fix it, i.e. on the first exception, the division class should be the active item , and after the first exception, the class should only be item .
+3
source to share
1 answer
If you are sure the problem is the class "active"
for the first element only, you can do something like this in your foreach:
<div class="carousel-inner">
<?php
$counter = 0;
//add a counter and check its value in your div.
//If it 0, echo active, otherwise nothing.
//In the end of your loop, the counter increases so it won't be 0 again
foreach ($testimonials as $t) {
//next div will echo "active", if the $counter==0
?>
<div class="item <?= ($counter == 0) ? "active" : "" ?>">
<div class="profile-circle" style="background-color: rgba(0,0,0,.2);">
<img class="profile-circle" src="<?php echo base_url(); ?>uploads/images/testimonials/<?php echo $t->picture; ?>" alt="testimonials_image">
</div>
<blockquote>
<p><?php echo $t->content; ?></p>
</blockquote>
</div>
<?php
//increase the $counter, or set it another value in order not to echo "active" again for the next loops
$counter++;
}
?>
</div>
+2
source to share