Created
June 17, 2014 23:26
-
-
Save drrobotnik/82e6766a7f32f6db88ae to your computer and use it in GitHub Desktop.
dynamic condition
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
function cv_acf_optional_template_parts( $slug = 'layouts/acf/', $names = array(''), $label = 'optional_layouts', $post_id = null ) { | |
while( has_sub_field( $label, $post_id ) ) { | |
foreach ( $names as $field ) { | |
if ( $field == get_row_layout() ){ | |
$template = str_replace('_', '-', $field); | |
get_template_part( 'layouts/acf/' . $template ); | |
} | |
} | |
} | |
} | |
cv_acf_optional_template_parts( 'layouts/acf/', array( 'header_gallery', 'intro_message' ), 'optional_layouts' ); | |
get_template_part( 'content', 'page' ); | |
cv_acf_optional_template_parts( 'layouts/acf/', array( 'info_columns', 'secondary_content', 'visual_divider' ), 'optional_layouts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
foreach ($fields as $field) {
if ($field == get_row_layout() ) {
get_template_part('content', $field);
}
}