Skip to content

Instantly share code, notes, and snippets.

@solid-pixel
Created July 24, 2017 13:44
Show Gist options
  • Save solid-pixel/b14cc0e43783fb9be3bbba2be103f4c1 to your computer and use it in GitHub Desktop.
Save solid-pixel/b14cc0e43783fb9be3bbba2be103f4c1 to your computer and use it in GitHub Desktop.
Use ACF Galleries field with ACF Flexible Content
<?php
// GALLERY LAYOUTS - Flexible Content
// check if the flexible content field has rows of data
if( have_rows('galleries') ):
// loop through the rows of data
while ( have_rows('galleries') ) : the_row();
if( get_row_layout() == '2_columns_gallery_layout' ):
$images50 = get_sub_field('2_columns_gallery_images');
if( $images50 ):
echo '<ul class="portfolio-grid-50">';
foreach( $images50 as $image50 ):
echo "<li><img src='" . $image50['url'] . "'></li>";
endforeach;
echo '</ul>';
endif;
elseif( get_row_layout() == '1_column_gallery_layout' ):
$images100 = get_sub_field('1_column_gallery_images');
if( $images100 ):
echo '<ul class="portfolio-grid-100">';
foreach( $images100 as $image100 ):
echo "<li><img src='" . $image100['url'] . "'></li>";
endforeach;
echo '</ul>';
endif;
endif;
endwhile;
else :
// no layouts found
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment