Flexible Content in ACF plugin – WordPress

  • This concept provides a simple, structured, block-based editor.
  • This field type functions as a blank canvas on which you can establish, generate, and manage content with total control, using layouts and subfields to customize the accessible blocks.

Settings

  • Layouts
    Defines the layouts available when editing content. Each layout contains Label, Name, Limit, Display and Field settings.
  • Button Label
    The text shown in the ‘Add Row’ button.
  • Minimum Layouts
    Sets a limit on how many layouts are required.
  • Maximum Layouts
    Sets a limit on how many layouts are allowed.

Template usage

The Flexible Content field returns a multi-dimensional array containing the layouts and their sub field values.

Accessing the value is done via the have_rows, the_row, get_sub_field, and the_sub_field functions.

Display layouts

<?php if( have_rows('content') ): ?>
    <?php while( have_rows('content') ): the_row(); ?>
        <?php if( get_row_layout() == 'paragraph' ): ?>
            <?php the_sub_field('paragraph'); ?>
        <?php elseif( get_row_layout() == 'image' ): 
            $image = get_sub_field('image');
            ?>
            <figure>
                <?php echo wp_get_attachment_image( $image['ID'], 'full' ); ?>
                <figcaption><?php echo $image['caption']; ?></figcaption>
            </figure>
        <?php endif; ?>
    <?php endwhile; ?>
<?php endif; ?>
List of field settings shown when setting up a Flexible Content field

Leave a comment

Your email address will not be published. Required fields are marked *