将while循环中的else语句放入一个div中

时间:2013-10-04 03:07:34

标签: php html wordpress

我有一个while循环,在while循环中有一个if-else语句。我想要做的就是将else语句的所有内容放入一个div中。它在Wordpress中。

我似乎无法理解它背后的逻辑......

<?php /* The loop */ 
        $i = 1;
        ?>
        <?php while ( have_posts() ) : the_post(); ?>
            <?php 
                static $count = 0;
                if ($count == 5) { break; }
                else {
                    ?>
                    <div class="content_container">
                    <?php
                        if($i == 1) {
                            ?><span style="width:370px;" class="main active"><?php the_post_thumbnail('full');?></span><?php
                        } else {
                            ?><span class="child nonactive"><?php the_post_thumbnail('full'); ?></span><?php
                        }
                        $i++;
                        $count++;
                    ?>
                    </div>
                    <?php
                } 
            ?>
        <?php endwhile; ?>

1 个答案:

答案 0 :(得分:1)

<div class="content_container">
<span <?php if($i == 1) { ?> style="width:370px;" class="main active" <?php } else {?> class="child nonactive" ><?php the_post_thumbnail('full');?></span>
<?php  }
$i++;
$count++;
?>
</div>