Last active
September 12, 2017 17:51
-
-
Save bob-moore/c28756bfdfd86683f006fb09868d77b0 to your computer and use it in GitHub Desktop.
Quick ACF page section stuff
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 | |
function display_acf_page_sections() { | |
// Construct ID | |
$id = !empty( get_sub_field('section_id') ) ? sprintf( ' id="%s"', esc_attr( get_sub_field('section_id') ) ) : ''; | |
// Construct class | |
$class = !empty( get_sub_field('section_class') ) ? sprintf( ' class="my_custom_class %s"', esc_attr( get_sub_field('section_class') ) ) : ' class="my_custom_class'; | |
// Construct style | |
$bg_image = get_sub_field('section_background_image'); | |
$bg_color = get_sub_field('section_background_image'); | |
if( empty( $bg_image ) && empty( $bg_color ) ) { | |
$style = ''; | |
} elseif( !empty( $bg_image ) ) { | |
$style = sprintf( ' style="background-image: url(%s)"', esc_url_raw( $bg_image ) ); | |
} elseif( !empty( $bg_color ) ) { | |
$style = sprintf( ' style="background-color: %s"', sanitize_hex_color( $bg_color ) ); | |
} | |
include get_stylesheet_directory() . '/partials/page_section.php'; | |
} | |
add_action( 'display_acf_page_sections' ); | |
// Add another or reuse logic for sub fields |
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
<section <?php echo $id . $class . $style; ?>> | |
<div class="sub_section_block_container row"> | |
<?php if( have_rows('section_block') ) : while( have_rows('section_block') ): the_row(); ?> | |
<?php do_action( 'display_sub_field' ); ?> | |
<?php endwhile; endif; ?> | |
</div> | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment