0

私はすでに単純なWordpressループを作成しましたが、今は少し異なってループするはずであり、開始方法やどこから開始するかさえわかりません。DIV class = "item-row-wrap"の中に、通常はDIV class="vinyl-wrap"をループするループがあります。

私の問題:3回ループしてから、新しいDIV class = "item-row-wrap"を作成し、DIV class = "vinyl-wrap"のループを3回再開して、続けてください。

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-->

4

1 に答える 1

0

ループ$iの前にvarを作成します。
ループが閉じる直前の値を上げる:(および閉じる) の$i++ 周りにモジュロチェックを設定します<div class="item-row-wrap"></div>

Moduloチュートリアル

完全な答えではありませんが、始めるには十分です。


次の例は、これを行う方法を示しています

<?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;
于 2012-08-28T09:57:05.583 に答える