Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Last active June 6, 2017 10:32
Show Gist options
  • Select an option

  • Save BinaryKitten/db96c4acb8427007acfb62476108c315 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryKitten/db96c4acb8427007acfb62476108c315 to your computer and use it in GitHub Desktop.
<?php
function render_acf_content( $field_name = 'page_layout', $post_id = null ) {
if ( ! $post_id ) {
$post_id = get_the_ID();
if ( is_home() ) {
$post_id = get_option( 'page_for_posts' );
}
}
$render_block = function () {
$row_layout = get_row_layout();
$templates = array(
apply_filters( 'template_include', "content_blocks/block-{$row_layout}.php" ),
apply_filters( 'template_include', 'content_blocks/block.php' ),
);
$located = locate_template( $templates, false, false );
if ( (string) $located !== '' ) {
include $located;
} elseif ( WP_DEBUG ) {
echo '<strong>' . $row_layout . '</strong>';
}
};
if ( have_rows( $field_name, $post_id ) ) {
$row_index = 0;
while ( have_rows( $field_name, $post_id ) ) {
the_row();
$render_block();
$row_index ++;
}
}
}
<?php
get_header();
while ( have_posts() ) :
the_post(); ?>
<div id="mainWrap">
<?php render_acf_content(); ?>
</div>
<?php
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment