当另一个查询存在时,为什么此查询无效?

时间:2015-07-28 20:26:04

标签: php wordpress twitter-bootstrap-3 owl-carousel

这让我疯了,我确定这是愚蠢的,但我太烧了,找不到它。我正在构建一个自定义WP主题,它有2个滑块,一个是默认的Bootstrap滑块,另一个是Owl Slider。在你告诉我“你为什么不使用Owl滑块的2个实例?”之前,我已经考虑过了,经过测试并且有效。但是,我很好奇为什么这不起作用。这是我的代码:

BOOTSTRAP Carousel:

<section id="panel4">
  <div class="container">
    <h2>Testimonials</h2>
  </div>
  <!-- container -->
  <div class="container-fluid">
    <?php $queryObject=new WP_Query( 'post_type=testimonial' ); // The Loop! if ($queryObject->have_posts()) { ?>
    <div id="carousel-testimonial" class="carousel slide" data-ride="carousel">
      <!-- Wrapper for slides -->
      <div class="carousel-inner" role="listbox">
        <?php while ($queryObject->have_posts()) {$queryObject->the_post(); ?>
        <div class="item ">
          <div class="container">
            <div class="row">
              <div class="col-sm-3 col-md-2 thumb-box">
                <img class="thumb" src="<?php echo types_render_field( " testimonial-avatar ", array( url => "true ", "width " => "400 ", "height " => "300 ", "proportional " => "true " ) );?>">
              </div>
              <div class="col-sm-9 col-md-10">
                <h3>"<?php echo types_render_field("testimonial-excerpt", array("argument1"=>"value1","argument2"=>"value2","argument2"=>"value2"));    ?>"</h3>

                <blockquote>
                  <?php echo types_render_field( "testimonial-text", array( "argument1"=>"value1","argument2"=>"value2","argument2"=>"value2")); ?></blockquote>
                <p class="sig">
                  <?php echo types_render_field( "testimonial-name", array( "argument1"=>"value1","argument2"=>"value2","argument2"=>"value2")); ?></p>
              </div>
            </div>
          </div>
        </div>
        <?php } ?>
      </div>
      <?php } ?>
      <!-- Controls -->
      <a class="left carousel-control" href="#carousel-testimonial" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="right carousel-control" href="#carousel-testimonial" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>

    </div>
    <!-- .carousel -->
  </div>
  <!-- .container -->
</section>

然后是OWL SLIDER

<?php if( have_rows( 'slider_photos') ): ?>

<div class="container-fluid">
  <div id="happy" class="owl-carousel">

    <?php while( have_rows( 'slider_photos') ): the_row(); // vars $image=g et_sub_field( 'slider_image'); ?>
    <div class="item-owl">
      <img class="img-responsive" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    </div>

    <?php endwhile; ?>

  </div>
  <!-- .carousel -->
</div>

<?php endif; ?>

现在,问题似乎出现在Bootstrap中。如果我把它取下,猫头鹰滑块工作。如果我添加2个猫头鹰滑块实例,它可以工作。如果我添加Bootstrap Carousel,只有Bootstrap工作,Owl什么都不显示(甚至在代码中都没有显示,就像它甚至不存在一样)

有谁能告诉我发生了什么以及如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Most likely you need to call padding-top:8px before wp_reset_postdata() in the Owl slider, to restore the global have_rows( 'slider_photos') object, that you override in your Bootstrap carousel loop.

The $post depends on the global have_rows('slider_photos') object.

Another option would be to use $post to specify what have_rows( 'slider_photos', $post_id ) you want to use.