Support

Account

Home Forums Add-ons Flexible Content Field Creating a line break after every fourth layout.

Solved

Creating a line break after every fourth layout.

  • Hey all,

    I’ve been developing a website using Advanced Custom Fields and have utilized the Flexible Content field so that blocks of information (or departments in this case) can be freely re-ordered on the edit page.

    I’ve designed the page to use four columns to display the secondary departments, however these blocks vary in height and cause the rows underneath to break resulting in a pretty messy layout (the messiness can be witnessed over at http://www.snoopersattic.co.uk).

    So my question is this: Is there a way to implement some form of code that can insert a line break (something along the lines of a CSS ‘clear:both;’) after every forth block/layout is listed, effectively creating a clear divide between rows.

    So far my PHP code for listing secondary departments looks like this:

    <?php  
    /*
    *  PROFILE BLOCK
    */ 
    while(has_sub_field("secondary_departments")): ?>
        
        <?php if(get_row_layout() == "secondary_department"): // layout: Content ?> 
        	<h3><?php the_sub_field('department_header'); ?></h3>
            <?php the_sub_field('department_description'); ?>
    
            <img src="<?php the_sub_field('department_thumbnail'); ?>" />
    	<?php endif; ?>
     
    <?php endwhile; ?>

    Any help with this would be HUGELY appreciated!

    Many thanks in advance,
    Phil

  • Hi @phillustration

    You can introduce a simple counter variable like so:

    
    <?php  
    /*
    *  PROFILE BLOCK
    */
    $i = 0;
    
    while(has_sub_field("secondary_departments")): $i++; ?>
        
        <?php if(get_row_layout() == "secondary_department"): // layout: Content ?> 
        	<h3><?php the_sub_field('department_header'); ?></h3>
            <?php the_sub_field('department_description'); ?>
    
            <img src="<?php the_sub_field('department_thumbnail'); ?>" />
    	<?php endif; ?>
    	
    	<?php if( $i == 4 ): $i = 0; ?>
    		<div class="clear"></div>
    	<?php endif; ?>
     
    <?php endwhile; ?>
    

    Thanks
    E

  • That’s perfect thanks Elliot,

    Looking back on my question I appreciate that it’s more of a general PHP task rather than ACF, so thanks for taking the time to solve it!

    Cheers,
    Phil

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

The topic ‘Creating a line break after every fourth layout.’ is closed to new replies.