Support

Account

Home Forums ACF PRO Insert code between get_row_layout()

Solved

Insert code between get_row_layout()

  • I need to add some codes between flexible content fields loop, but I don’t know which is the syntax. I have this code:

    <?php if( have_rows('blocks') ):?>
        <?php while ( have_rows('blocks') ) : the_row();?>
            
            <?php if( get_row_layout() == 'full_screen' ):?>
    
             <?php elseif( get_row_layout() == 'box' ):?>
                  <div class="row">
                          <div class="col-sm-3">
                              <!--content-->
                          </div>
                   </div>
              
            <?php endif;?>
            
        <?php endwhile;
    
    	else :

    We expect the output to be like this:

    <div class="row">
     <div class="col-sm-3"><!--content--></div>
    </div>
    <div class="row">
     <div class="col-sm-3"><!--content--></div>
    </div>

    Which code should I add to get this outcome?

    <div class="row">
         <div class="col-sm-3"><!--content--></div>
         <div class="col-sm-3"><!--content--></div>
    </div>

    I need to include the generated code in another div

    Thank you!

  • Hi @marco-b

    You should be able to achieve that using this code:

    <?php if( have_rows('blocks') ):?>
        <div class="row">
            <?php while ( have_rows('blocks') ) : the_row();?>
                
                <?php if( get_row_layout() == 'full_screen' ):?>
    
                 <?php elseif( get_row_layout() == 'box' ):?>
                      
                      <div class="col-sm-3">
                          <!--content-->
                      </div>
                  
                <?php endif;?>
                
            <?php endwhile;
        </div>
    	else :

    I hope this helps.

  • Thank you @james for the answer.
    Using your code i can include all the layouts inside a <div class=’row’></div> , but i need to include only the “box” layout inside a <div class=’row’></div>, not all the generated code.

    If i have this code:

    <?php if( have_rows('blocks') ):?>
         <div class="row">
        <?php while ( have_rows('blocks') ) : the_row();?>
            
            <?php if( get_row_layout() == 'full_screen' ):?>
    
               <div class="fullscreen"><!--content--></div>
    
                <?php elseif( get_row_layout() == 'box' ):?>
                  <div class="row">
                          <div class="col-sm-3">
                              <!--content-->
                          </div>
                   </div>
              
               <?php endif;?>
            </div>
        <?php endwhile;
    
    	else :

    We expect the output to be like this:

    <div class="row">
      <div class="fullscreen"><!--content--></div>
      <div class="col-sm-3"><!--content--></div>
      <div class="col-sm-3"><!--content--></div>
    </div>

    But i need this:

    <div class="fullscreen"><!--content--></div>
    <div class="row">
      <div class="col-sm-3"><!--content--></div>
      <div class="col-sm-3"><!--content--></div>
    </div>

    Someone can help me?

    Thank you!

  • Hi @marco-b

    I believe you can do it like this:

    <?php if( have_rows('blocks') ):?>
        <?php $i = 0; ?>
        <?php while ( have_rows('blocks') ) : the_row();?>
            
            <?php if( get_row_layout() == 'full_screen' ):?>
    
                <div class="fullscreen"><!--content--></div>
    
            <?php elseif( get_row_layout() == 'box' ):?>
            
                <?php if($i == 0){ ?>
                <div class="row">
                <?php
                }
                $i++;
                ?>
                    <div class="col-sm-3"><!--content--></div>
              
            <?php endif;?>
    
        <?php endwhile;
                </div>
    	else :

    Hope this helps!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.