仅限活动来自carsouel滑块的一项来自Dynamic COntent

时间:2016-05-07 03:29:27

标签: php wordpress carousel

<section class="product_section">
<div class="container">
    <div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="false">
     <!-- Wrapper for slides -->
        <div class="carousel-inner" role="listbox">
            <?php $loop = new WP_Query( array( 'post_type' => 'product_theme', 'posts_per_page' => -1 ) ); ?>
            <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <div class="item <?php if($c==1) { ?> active<?php } ?>">
                <div class="row">
                    <div class="col-xs-12 col-sm-7 col-md-7 product_image">
                        <?php twentysixteen_post_thumbnail(); ?>
                    </div>
                    <div class="product_detail col-xs-12 col-sm-5 col-md-5">
                        <h2><?php the_title(); ?></h2>
                            <?php echo get_post_meta(get_the_ID(), 'my_custom_fields_custom-field-3', TRUE);?>/span>
                                <?php the_content(); ?>
                                <a href="<?php echo get_post_meta(get_the_ID(), 'my_custom_fields_custom-field-1', TRUE);?>" target="_blank" class="live_demo">Live Demo</a>
                                <a href="<?php echo get_post_meta(get_the_ID(), 'my_custom_fields_custom-field-2', TRUE);?>" class="buy_know">View Details</a>
                    </div><!-- product_detail col-xs-12-->
                </div><!--ROW -->
            </div><!-- itEM-->
            <?php  endwhile; $c=$c+1; wp_reset_query(); ?>
        </div><!--carousel-inner -->

        <!-- Left and right controls -->
        <a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div><!--myCarousel -->
</div><!--container -->
</section>

我已经尝试过这个代码,但它会激活所有项目NOt一个项目,任何人都有解决方案。我想只激活项目中的其他项目,所以,我将轮换项目。

1 个答案:

答案 0 :(得分:0)

你可以做这样的事情,当然这是 laravel ,但我相信你会明白这一点。

<div class="carousel-inner" role="listbox">
  @if(count($images) > 0)
  <?php $a=1;?>
    @foreach($images as $image)
        <div class="item <?php if($a==1){?>active<?php }?>">
          <img src="{{ $image->image_path }}" alt="{{ $image->caption }}" class="img-thumbnail gallery">
           <div class="carousel-caption">
              <!-- <h2>{{ $image->caption }}</h2> -->
               <p class="message">{{ $image->description }}</p>
             </div>
          </div>
  <?php $a++;?>
@endforeach
@else
   <div class="alert alert-danger"><span>No images</span></div>
@endif
</div>  <!-- end of Wrapper for slides -->