簡體   English   中英

循環排列2種不同的帖子布局

[英]2 different post layouts in a loop

我剛剛創建了美麗的循環

 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
 <div class="row sectionrow" onclick="void(0)">
 <div class="col-sm-4 sectionrecipes" style="background-image:url('<?php echo the_field(background_image_title); ?>');">
  <div class="textsmall" >
 <?php the_field(titlebreak); ?>
    </div>
 </div>
 <div class="col-sm-8">
  <div class="sectionrecipes" style="background-image:url('<?php echo the_field(background_image_detail); ?>');">
     <div class="textbigrecipes">  
        <div class="inner">
    <?php the_excerpt(); ?> 
       <a href="<?php the_permalink(); ?>"><button type="button" class="btn btn-default">READ MORE</button></a>
        </div>
     </div>
  </div>
 </div>
 </div>
</div>

但我想在第二篇文章中將bootstrap div的位置反轉,並在第三篇文章中返回原始內容,然后...。

  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <div class="row sectionrow" onclick="void(0)">
  <div class="col-sm-8">
  <div class="sectionrecipes" style="background-image:url('<?php echo the_field(background_image_detail); ?>');">
     <div class="textbigrecipes">  
        <div class="inner">
    <?php the_excerpt(); ?> 
       <a href="<?php the_permalink(); ?>"><button type="button" class="btn btn-default">READ MORE</button></a>
        </div>
     </div>
   </div>
  </div>
   </div>
    <div class="col-sm-4 sectionrecipes" style="background-image:url('<?php echo the_field(background_image_title); ?>');">
  <div class="textsmall" >
 <?php the_field(titlebreak); ?>
    </div>
 </div>

</div>

可能嗎?

1. First declare a variable Outside the loop (like as $i =1), 
  1. 然后檢查條件。 我的模式

     example: if($i% 2 == 0) { -----layout First code----- }else { -----layout Second code----- } 
  2. 遞增變量值($ i ++)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM