Skip to content

Instantly share code, notes, and snippets.

@joetower
Created October 14, 2016 16:10
Show Gist options
  • Save joetower/c8aee2f81ad5b9784335d4a39cc293b6 to your computer and use it in GitHub Desktop.
Save joetower/c8aee2f81ad5b9784335d4a39cc293b6 to your computer and use it in GitHub Desktop.
WordPress flexible content include example
<?php
/**
* ACF fields for pages using this template parent - page.flexible.php
*
*/
?>
<?php
// check if the flexible content field has rows of data
?>
<?php if( have_rows('page_content_group') ):?>
<article>
<?php while ( have_rows('page_content_group') ) : the_row();?>
<?php if( get_row_layout() == 'image-block' ):
$image = get_sub_field('image');
?>
<!-- image full-width-->
<section class="component-block image-block">
<div class="limiter">
<figure>
<img <?php fourkitchens_responsive_image(get_sub_field( 'image' ),'featured-image-medium','800px'); ?> alt="<?php echo $image['alt'] ?>" />
</figure>
</div>
</section>
<?php endif; ?>
<?php if(get_row_layout() == 'hr-block' ): ?>
<!-- heading callout with optional alignment class-->
<div class="component-block hr-block <?php if( get_sub_field('horizontal_rule') ): ?> <?php the_sub_field('horizontal_rule'); ?><?php endif; ?>">
<div class="limiter">
<hr>
</div>
</div>
<?php endif; ?>
<?php if(get_row_layout() == 'content-header' ): ?>
<!-- heading with optional alignment class-->
<div class="<?php if( get_sub_field('alignment-class') ): ?> <?php the_sub_field('alignment-class'); ?><?php endif; ?>">
<div class="limiter">
<h2<?php if( get_sub_field('anchor_link_value') ): ?> id="<?php the_sub_field('anchor_link_value'); ?>"<?php endif; ?>><?php the_sub_field('heading'); ?></h2>
</div>
</div>
<?php endif; ?>
</article>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment