2013-10-04 86 views
0

我有一個while循環,while循環中有一個if-else語句。我想要做的就是將else語句的所有內容放入一個div中。它在Wordpress中。將其他語句放在while循環中放入一個div

我似乎無法得到它背後的邏輯..

<?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
<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> 
+0

這是沒有做到這一點。我只想把else語句放入ONE div中。 – user2772219

+0

看得不錯,其中一個div – user2092317

+0

無法理解,請解釋 – user2092317