2017-02-04 64 views
1

我试图将Bootstrap旋转木马集成到我的Wordpress主题中作为一个推荐滑块。证明书和徽标显示(我使用自定义帖子类型),但唯一没有显示的是旋转木马指示器。我已经浏览了很多Stackoverflow问题和其他网页,但我找不到解决方案。Bootstrap旋转木马指标不显示在Wordpress中

有人可以看看我的代码,看看我能做些什么来解决它吗?感谢您的帮助。

<ol class="carousel-indicators"> 
      <?php 
       $args = array(
        'post_type' => 'testimonial', 
        'orderby' => 'post_id', 
        'order'  => 'ASC' 
       ); 
       $loop = new WP_Query($args); 
       $banner_count = 0; 
       while ($loop->have_post()) : $loop->the_post(); 

       if ($banner_count == 0){ 
        $active_item = 'active'; 
       } 
       else { 
        $active_item = ''; 
       } 
      ?> 
      <li data-target="#quote-carousel" data-slide-to="<?php echo $banner_count; ?>" class="<?php echo $active_item; ?>"></li> 
      <?php $banner_count++; endwhile; ?> 
      </ol> 



      <!-- Carousel Slides/Quotes --> 


      <div class="carousel-inner"> 
      <?php 
       $loop = new WP_Query($args); 
       $banner_count = 0; 
       while ($loop->have_posts()) : $loop->the_post(); 
       if ($banner_count == 0){ 
        $active_item = 'active'; 
       } 
       else { 
        $active_item = ''; 
       } 
      ?> 
       <!-- Quote 1 --> 
       <div class="item <?php echo $active_item; ?>"> 
        <blockquote> 
         <div class="row"> 
          <div class="col-sm-3 text-center"> 
          <img class="img-circle"> 
          <?php 
           if (has_post_thumbnail()) { 
            the_post_thumbnail(array(200, 100)); 
           } 
          ?> 
          </div> 
          <div class="col-sm-9"> 
          <?php the_content(); ?> 
          <small><?php the_title(); ?></small> 
          </div> 
         </div> 
        </blockquote> 
       </div> 
      <?php $banner_count++; endwhile; ?> 
      </div> 
+0

检查你的css中.carousel指标和.carousel指标李在cosole你可能会发现它为什么不显示。 –

+0

分享你的网站网址 –

+0

嘿monsty - 我试图做同样的事情,但你有问题。你在使用BS4吗?如果是这样,请你能分享整个代码片段,以使其作为推荐滑块工作吗?谢谢! – user3502952

回答

1

您错过了s关于have_posts()的指标。

while ($loop->have_post()) : $loop->the_post(); 

应该是:

while ($loop->have_posts()) : $loop->the_post(); 

我也建议你查询移动到顶部,并运行它,而不是一次两次。

<?php 
$args = array(
    'post_type' => 'testimonial', 
    'orderby' => 'post_id', 
    'order'  => 'ASC' 
); 

$loop = new WP_Query($args); 

if ($loop->have_posts()) : ?> 
    <ol class="carousel-indicators"> 
     . . . 
     WHILE HERE FOR LIST ITEMS 

    </ol> 

    <?php $loop->rewind_posts(); // reset the loop and re-use ?> 

    <div class="carousel-inner"> 
     . . . 
     WHILE HERE TO LOOP THROUGH ITEMS 
     . . . 
    </div> 

    <?php 
endif; 
+0

哇,好点!它现在有用,谢谢!我一直盯着那些代码很久,所以我没有注意到任何错误。我也会尝试你的建议:) – monsty