2012-08-28 55 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