2017-07-19 157 views
3

我是新來的笨,我不知道如何在笨顯示旋轉木馬滑塊錯誤在旋轉木馬滑塊笨

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

這是代碼,其實我知道是什麼錯誤,但我不知道如何糾正它,即在第一次執行時,部門級別必須是活動項目並且在首次執行後,該類別只需要項目

+1

爲什麼不你在循環中添加一個簡單的計數器?如果爲0,則回顯「有效」。如果你確定這是問題,我可以用代碼回答你。 – GeorgeGeorgitsis

+0

是的,確定是問題所在 –

回答

2

如果您確信該問題是隻有第一個元素的類"active",你可以做這樣的事情,在您的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>