user2772219
user2772219

Reputation: 129

Put else statement that is inside a while loop into one div

I have a while loop and inside the while loop there is an if-else statement. All I want to do is put all the contents of the else statements into one div. It's in Wordpress.

I can't seem to get the logic behind it..

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

Upvotes: 0

Views: 125

Answers (1)

user2092317
user2092317

Reputation: 3338

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

Upvotes: 1

Related Questions