vendredi 9 novembre 2018

Using foreach to print three items or first three items

I am using foreach to print all elements and from this taking first elemments to use below block structure. first element place under col-md-8 and second and third place under col-md-4 and do not have any issue with CSS. it's not working the way I have done. How can I use foreach to place first items inside it? or divide into 3 items per whole row?

<div class="section">       
    <div class="container"> <!-- container -->
       <?php $i = 0;
            foreach($view->result as $result) {

        <div id="hot-post" class="row hot-post"> 
      <?php if(i = 1) { // first item goes here            
            <div class="col-md-8 hot-post-left">            
                <div class="post post-thumb"> 
                      // inside header and body common for all
                    </div>
                </div>
            </div>
            } ?>

     <?php if(i = 2 || i = 3) {
            <div class="col-md-4 hot-post-right">
          <?php if(i = 2){ ?>   // second item goes here     
                <div class="post post-thumb">
                        // inside header and body common for all
                </div>

       <?php } if(i = 3){ ?>  // third item goes here                           
                <div class="post post-thumb"> 
                       // inside header and body common for all
                </div>
            </div> 
        <?php } ?>      
        </div> <!-- /row -->        
   <?php } ?>   
    </div><!-- /container -->       
</div>

Aucun commentaire:

Enregistrer un commentaire