2012-08-28 52 views
0

我已经创建了一个简单的Wordpress循环,但现在它应该循环有点不同,我不知道如何启动,甚至从哪里开始。我有内部DIV class =“item-row-wrap”我的循环通常通过DIV class =“vinyl-wrap”循环。WordPress的循环计数

我的问题:我想循环三次,然后创建一个新的DIV class =“item-row-wrap”并重新开始循环DIV class =“vinyl-wrap”三次...然后去上和

Here is the code: 
<code> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<?php if(get_field('artist-repeater')): while(has_sub_field('artist-repeater')): ?> 

<div class="item-row-wrap"> <!--START of item-row-wrap--> 

    <div class="vinyl-wrap"> <!--START of vinyl-wrap--> 
     <?php if(get_sub_field('play-repeater-songlink')): ?> 
      <a class="play" href='<?php the_sub_field('play-repeater-songlink'); ?>' target="_blank"></a> 
     <?php endif; ?> 
     <?php if(get_sub_field('moreinfo-repeater-song')): ?> 
      <a class="more-info" href='<?php the_sub_field('moreinfo-repeater-song'); ?>' target="_blank"></a> 
     <?php endif; ?> 
     <div class="vinyl-cover"> 
      <div class="vinyl-cover-plastik"></div> 
      <?php if(get_sub_field('album-repeater-image')): ?> 
      <?php $image = wp_get_attachment_image_src(get_sub_field('album-repeater-image'), 'thumbnail'); ?> 
      <img class="album-cover-art" src="<?php echo $image[0]; ?>" alt="<?php get_the_title(get_field('album-repeater-image')) ?>" /> 
      <?php endif; ?> 
     </div> <!--End of vinyl-cover--> 
     <div class="likeit"> 
      <?php if(function_exists(getILikeThis)) getILikeThis('get'); ?> 
     </div> 
     <div class="artist-name-wrap"> 
      <div class="artist-wrap-left"></div> 
      <div class="artist-wrap-mid"> 
       <p><?php the_title(); ?></p> 
      </div> 
      <div class="artist-wrap-right"></div> 
     </div> <!--End of artist-name-wrap--> 
     <div style="clear:both;"></div> 
     <div class="song-name-wrap"> 
      <div class="song-wrap-left"></div> 
      <div class="song-wrap-mid"> 
       <?php if(get_sub_field('song-repeater-name')): ?> 
        <p><?php the_sub_field('song-repeater-name'); ?></p> 
       <?php endif; ?> 
      </div> 
      <div class="song-wrap-right"></div> 
     </div> <!--end of song-name-wrap--> 


    </div> <!--END OF VINYL-WRAP--> 


     <?php endwhile; endif; ?> 

    <?php endwhile; ?> 
    <?php wp_reset_query(); ?> 
    <?php else: ?> 
     Yht&auml;&auml;n artikkelia ei ole viel&auml; julkaistu. 
    <?php endif; ?> 

</div> <!--END OF ITEM-ROW-WRAP--> 

回答

0

使循环之前$i变种。
提升价值就在环之前关闭:$i++ 设置一个模检查<div class="item-row-wrap">左右(与封口</div>

Modulo tutorial

不是一个完整的答案,但足以让你开始。

例如
下面的例子显示,你应该怎么做这个

<?php 
$i = 0; 
if (have_posts()) : while (have_posts()) : the_post(); 
if(get_field('artist-repeater')): while(has_sub_field('artist-repeater')): 

    if ($i % 3 == 0) { 
     echo '<div class="item-row-wrap"> <!--START of item-row-wrap-->'; 
    } 
    $i++; // up the numer of looped 
?> 
DO your magic 
<?php 
    if ($i % 3 == 0) { 
     echo '</div> <!--END OF ITEM-ROW-WRAP-->'; 
    } 


endwhile; //end have_posts() 
endif; 
+0

怎么做我需要包装的模块?它会起作用。我找到了一个使用模运算符的教程: [Tutorial](http://www.devchunks.com/web-development/using-the-php-modulus-operator/) – Pullapooh

+0

您给出的教程完全符合您的要求,它是通过3。'if($ i%3 == 0){/ *做你的魔法* /}' – janw

+0

对不起,请问,但你能让我举一个例子,我真的不知道如何开始在这里:/ – Pullapooh