Flexible Content lets editors build a page from sections (called layouts) in any order: a hero, then a text block, then a quote, and so on.
Set it up:
- Add a field of type Flexible Content, labelled for example Page sections.
- Click Add Layout for each kind of section. Give it a label and name, choose its Display (Block, Table or Row), an optional Min and Max, and add its own sub fields. Example layouts: Hero (headline, background image), Text block (WYSIWYG Editor), Quote (Text Area).
- Optional: Button Label ("Add section") and Minimum Layouts / Maximum Layouts.
Layouts can be duplicated, reordered and collapsed in the builder, just like fields.
As an editor: click the button, then pick a layout under Choose a layout. Drag sections to reorder them. Each section has Add layout above, Duplicate layout, Collapse / expand layout and Remove layout.
In a template:
<?php while ( sgct_have_rows( 'page_sections' ) ) : sgct_the_row(); ?>
<?php if ( 'hero' === sgct_get_row_layout() ) : ?>
<h1><?php echo esc_html( sgct_get_sub_field( 'headline' ) ); ?></h1>
<?php elseif ( 'text_block' === sgct_get_row_layout() ) : ?>
<?php echo wp_kses_post( sgct_get_sub_field( 'body' ) ); ?>
<?php endif; ?>
<?php endwhile; ?>
