我是codeigniter的新手,我不知道如何在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>
这是代码,实际上我知道错误是什么,但我不知道如何纠正它,即,在第一次执行时,分类必须是活动项目,并且在第一次执行之后,该类只需要是项目.
解决方法:
如果您确定问题只是第一个元素的“活动”类,那么您可以在foreach中执行以下操作:
<div class="carousel-inner">
<?PHP
$counter = 0;
//add a counter and check its value in your div.
//If it's 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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。