php – Carousel滑块codeigniter中的错误

我是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>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...