2017-04-05 103 views
0

需要帮助,使循环是这样的: http://prntscr.com/eswtytWordPress的自循环

随着2箭头样式(左,右)。

1)与左箭头2)与左箭头项项 3)与右箭头4)项与项右箭头 5)与左箭头6)与左箭头 等物品的物品...

我现在的循环:

<?php 
        $services = get_posts(array(
         'meta_query' => array(
          array(
           'key' => 'enable_service_in_homepage', 
           'compare' => '==', 
           'value' => '1' 
          ) 
         ) 
        )); 

        if($services): 
       ?> 
       <?php foreach($services as $post): setup_postdata($post) ?> 
        <div class="col-sm-6 nopadding"> 
         <div class="item item-left"> 
          <div class="col-sm-6 nopadding hidden-xs"> 
           <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(700, 500)); ?></a> 
           <div class="arrow-left"></div> 
          </div> 
          <div class="col-md-6 nopadding"> 
           <div class="content"> 
            <h2><?php the_title(); ?></h2> 
            <p><?php echo wp_trim_words(get_the_content(), 35, '...'); ?></p> 
            <a href="<?php the_permalink(); ?>" class="service-button"><?php echo __('ƏTRAFLI','altus'); ?></a> 
           </div> 
          </div> 
         </div> 
        </div> 
        <!-- Start right arrow --> 
         <div class="col-sm-6 nopadding"> 
          <div class="item item-right"> 
           <div class="col-md-6 nopadding"> 
            <div class="content"> 
             <h2><?php the_title(); ?></h2> 
             <p><?php echo wp_trim_words(get_the_content(), 35, '...'); ?></p> 
             <a href="<?php the_permalink(); ?>" class="service-button"><?php echo __('ƏTRAFLI','altus'); ?></a> 
            </div> 
           </div> 
           <div class="col-sm-6 nopadding hidden-xs"> 
            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(700, 500)); ?></a> 
            <div class="arrow-right"></div> 
           </div> 
          </div> 
         </div> 
        <!-- End right arrow --> 
       <?php endforeach; ?> 
       <?php wp_reset_postdata(); ?> 
       <?php endif; ?> 
+0

那么,这有什么问题? – vlasits

+0

抱歉我的英文不好。 即时需要帮助使图片中的布局,在我的循环现在只有左箭头,有评论<! - 开始右箭头 - >在哪里开始右箭头另一个布局。需要这样的网格: 1)项目与左箭头2)项目与左箭头 3)项目与右箭头4)项目与右箭头 5)项目与左箭头6)项目与左箭头 – Gr1m0n

+0

我会建议您将省略代码的后半部分(从右箭头开始评论及其后),并从代码的顶部删除“左箭头”类,并将代码替换为在“左箭头”和“右箭头”之间交替显示的代码。对”。你是否在寻找帮助来找出如何交替? – vlasits

回答

0

有可能是这样做的更清洁的方式,但你可以array_chunk()完成它:

<?php 
$services = get_posts(array(
    'meta_query' => array(
     array(
      'key' => 'enable_service_in_homepage', 
      'compare' => '==', 
      'value' => '1' 
     ) 
    ) 
)); 
?> 
<?php if($services): ?> 
    <?php $services_chunked = array_chunk($services, 2); ?> 
    <?php foreach($services_chunked as $key => $posts): ?> 
     <?php $alignment = $key % 2 ? "left" : "right"; ?> 
     <?php foreach ($posts as $post) : setup_postdata($post); ?> 
      <div class="col-sm-6 nopadding"> 
       <div class="item item-<?= $alignment ?>"> 
        <div class="col-sm-6 nopadding hidden-xs"> 
         <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(700, 500)); ?></a> 
         <div class="arrow-<?= $alignment ?>"></div> 
        </div> 
        <div class="col-md-6 nopadding"> 
         <div class="content"> 
          <h2><?php the_title(); ?></h2> 
          <p><?php echo wp_trim_words(get_the_content(), 35, '...'); ?></p> 
          <a href="<?php the_permalink(); ?>" class="service-button">Altus</a> 
         </div> 
        </div> 
       </div> 
      </div> 
     <?php endforeach; ?> 
     <?php wp_reset_postdata(); ?> 
    <?php endforeach; ?> 
<?php endif; ?>