Wordpress循环重复两次

时间:2016-05-12 19:21:55

标签: wordpress loops

你好我在WordPress中有一个while循环,我在循环的第一个实例上添加了一个活动类,这个工作正常,但是同样的实例然后在没有活动类的情况下再次重复。

这是我的代码,非常感谢任何帮助。

<div class="carousel-inner" role="listbox">

                        <?php
          query_posts( array( 'post_type' => 'deal','dealtype' => 'deals' ) );
          while (have_posts()) : the_post(); 
?>

                                <?php if( $wp_query->current_post == 0 && !is_paged() ) {  ?>

                                 <div class="item active">
                           <div class="row">
                              <div class="col-md-6 col-md-offset-1 col-sm-6 col-sm-offset-1">
                                <?php 

                $thumb_id = get_field('featured_image'); 
                $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true);
                $thumb_url = $thumb_url_array[0];

?>  
                                 <img src="<?php echo $thumb_url; ?>" class="img-responsive" alt="" />
                              </div>
                              <div class="col-md-4 col-sm-4">
                                 <div class="featuredContent">
                                    <div class="contentTitle">
                                       <h2><?php echo get_the_title(); ?> </h2>
                                    </div>
                                    <div class="contentDetails">
                                       <p><?php echo get_field('sub_title'); ?>
                                       </p>
                                    </div>
                                    <?php if(get_field('max_amount')) { ?>
                                    <div class="contentDetails">
                                       <p>Up to 
                                       <?php the_field('max_amount'); ?>


                                       Shares</p>
                                    </div>
                                    <?php } ?>
                                    <!--
                                    <div class="contentLink">
                                       <p><a href="#">invest now</a></p>
                                    </div>
                                    <div class="contentLink">
                                       <p><a href="#">follow offering</a></p>
                                    </div>
                                    -->
                                 </div>
                              </div>
                           </div>
                        </div>

                                <?php }  ?>


                        <div class="item">
                           <div class="row">
                              <div class="col-md-6 col-md-offset-1 col-sm-6 col-sm-offset-1">
                                <?php 

                $thumb_id = get_field('featured_image'); 
                $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true);
                $thumb_url = $thumb_url_array[0];

?>  
                                 <img src="<?php echo $thumb_url; ?>" class="img-responsive" alt="" />
                              </div>
                              <div class="col-md-4 col-sm-4">
                                 <div class="featuredContent">
                                    <div class="contentTitle">
                                       <h2><?php echo get_the_title(); ?> </h2>
                                    </div>
                                    <div class="contentDetails">
                                       <p><?php echo get_field('sub_title'); ?>
                                       </p>
                                    </div>
                                    <?php if(get_field('max_amount')) { ?>
                                    <div class="contentDetails">
                                       <p>Up to 
                                       <?php the_field('max_amount'); ?>


                                       Shares</p>
                                    </div>
                                    <?php } ?>
                                    <!--
                                    <div class="contentLink">
                                       <p><a href="#">invest now</a></p>
                                    </div>
                                    <div class="contentLink">
                                       <p><a href="#">follow offering</a></p>
                                    </div>
                                    -->
                                 </div>
                              </div>
                           </div>
                        </div>






                      <?php endwhile; // end of the loop. ?>  






                     </div>

1 个答案:

答案 0 :(得分:0)

相信您需要在else语句结束后添加<?php if ($wp_query->current_post == 0 && !is_paged() ) { ?>语句。应该看起来像这样:

<div class="carousel-inner" role="listbox">

                    <?php
      query_posts( array( 'post_type' => 'deal','dealtype' => 'deals' ) );
      while (have_posts()) : the_post(); 
?>

                            <?php if ( $wp_query->current_post == 0 && !is_paged() ) { ?>

                             <div class="item active">
                       <div class="row">
                          <div class="col-md-6 col-md-offset-1 col-sm-6 col-sm-offset-1">
                            <?php 

            $thumb_id = get_field('featured_image'); 
            $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true);
            $thumb_url = $thumb_url_array[0];

?>  
                             <img src="<?php echo $thumb_url; ?>" class="img-responsive" alt="" />
                          </div>
                          <div class="col-md-4 col-sm-4">
                             <div class="featuredContent">
                                <div class="contentTitle">
                                   <h2><?php echo get_the_title(); ?> </h2>
                                </div>
                                <div class="contentDetails">
                                   <p><?php echo get_field('sub_title'); ?>
                                   </p>
                                </div>
                                <?php if(get_field('max_amount')) { ?>
                                <div class="contentDetails">
                                   <p>Up to 
                                   <?php the_field('max_amount'); ?>


                                   Shares</p>
                                </div>
                                <?php } ?>
                                <!--
                                <div class="contentLink">
                                   <p><a href="#">invest now</a></p>
                                </div>
                                <div class="contentLink">
                                   <p><a href="#">follow offering</a></p>
                                </div>
                                -->
                             </div>
                          </div>
                       </div>
                    </div>

                            <?php } else {  ?>


                    <div class="item">
                       <div class="row">
                          <div class="col-md-6 col-md-offset-1 col-sm-6 col-sm-offset-1">
                            <?php 

            $thumb_id = get_field('featured_image'); 
            $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true);
            $thumb_url = $thumb_url_array[0];

?>  
                             <img src="<?php echo $thumb_url; ?>" class="img-responsive" alt="" />
                          </div>
                          <div class="col-md-4 col-sm-4">
                             <div class="featuredContent">
                                <div class="contentTitle">
                                   <h2><?php echo get_the_title(); ?> </h2>
                                </div>
                                <div class="contentDetails">
                                   <p><?php echo get_field('sub_title'); ?>
                                   </p>
                                </div>
                                <?php if(get_field('max_amount')) { ?>
                                <div class="contentDetails">
                                   <p>Up to 
                                   <?php the_field('max_amount'); ?>


                                   Shares</p>
                                </div>
                                <?php } ?>
                                <!--
                                <div class="contentLink">
                                   <p><a href="#">invest now</a></p>
                                </div>
                                <div class="contentLink">
                                   <p><a href="#">follow offering</a></p>
                                </div>
                                -->
                             </div>
                          </div>
                       </div>
                    </div>

                        <?php } ?>




                  <?php endwhile; // end of the loop. ?>  






                 </div>