Skip to content

Instantly share code, notes, and snippets.

@chuckmo
Last active March 10, 2017 13:19
Show Gist options
  • Save chuckmo/76e45df970bb061c7ab22b9fc4ef95dd to your computer and use it in GitHub Desktop.
Save chuckmo/76e45df970bb061c7ab22b9fc4ef95dd to your computer and use it in GitHub Desktop.
Loading ACF Flexible Content partials
<?php
function self_get_page_sections($path = ''){
// check if the flexible content field has rows of data
if( have_rows('content_blocks') ):
// loop through the rows of data
while ( have_rows('content_blocks') ) : the_row();
$cur_sect = get_row_layout();
// all partial files are in the "/partials/" directory and are named the same
// as the Flexible Content block's slug
$filepath = TEMPLATEPATH . '/partials/' . $path . $cur_sect . '.php';
if(file_exists( $filepath )){
// the partial
include($filepath);
}
endwhile;
else :
// no layouts found
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment