0

私のワードプレスブログに10件の投稿があり、次のようなものにしたいです:div class = "something1" post1 post5 post9 / div

div class = "something2" post2 post6 post10 / div div class = "something3" post3 post7 post4 post8 / div

わかりませんが、必要です。助けてください。

4

1 に答える 1

0

ループでは、phpを使用してdivをインクリメントする必要があります。私はこれをテストしていませんが、これは機能するはずです:

<div class="yourClass">
<?php
    $myCustomClass = 0;
    $args = array
    (
        'posts_per_page' => 4,
        'orderby'     => 'name',
        'order'       => 'DEC',
        'post_type'   => 'post',
        'post_status' => 'publish'
    );
    $loop = new WP_Query( $args );

    while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <?php $myCustomClass++ ?>

            <div class="myCustomClass-<?php echo $myCustomClass;?>">

                <h2>
                    <a href="<?php the_permalink();?>">
                        <?php the_title(); ?>
                    </a>
                </h2>

                <div class="my-post-content">

                    <?php the_content(); ?>

                </div>

            </div>
<? endwhile; ?>
</div>
于 2012-08-15T09:27:15.987 に答える