Last active
March 10, 2017 13:19
-
-
Save chuckmo/76e45df970bb061c7ab22b9fc4ef95dd to your computer and use it in GitHub Desktop.
Loading ACF Flexible Content partials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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