Last active
January 20, 2022 10:51
-
-
Save christiaansnoei/b669c88290c3c43e06f57d46376a5224 to your computer and use it in GitHub Desktop.
Loop through each row of a flexible content field.
This file contains hidden or 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 | |
$flexible_content = ''; | |
if( have_rows('partials', get_queried_object_id()) ): | |
while( have_rows('partials', get_queried_object_id()) ): the_row(); | |
$row_layouts = [ | |
'example-1', | |
'example-2', | |
'example-3', | |
]; | |
foreach( $row_layouts as &$layout ) { | |
if( get_row_layout() == $layout ): | |
ob_start(); | |
include( get_template_directory() . '/template-parts/partials/'.$layout.'.php' ); | |
$flexible_content .= ob_get_clean(); | |
endif; | |
} | |
endwhile; | |
endif; | |
echo $flexible_content; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment