Skip to content

Instantly share code, notes, and snippets.

@kdankov
Last active May 11, 2020 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdankov/5f921af0bc23ab99eb37e40aeeb128e7 to your computer and use it in GitHub Desktop.
Save kdankov/5f921af0bc23ab99eb37e40aeeb128e7 to your computer and use it in GitHub Desktop.
<?php
/**
* Template Name: ACF Sections
*/
get_header();
$fields = get_fields();
foreach ( $fields as $prefix => $section ) {
$template_path = get_template_directory() . '/sections/' . $section['template_path'] . '.php';
if ( file_exists( $template_path ) ) {
require $template_path;
}
}
get_footer();
<?php
/**
* Example Section
*/
$section_title = $section['title'];
$short_desc = $section['description'];
$cta_primary = $section['cta_primary'];
$cta_secondary = $section['cta_secondary'];
$bgrd_desktop = $section['background_image_desktop'];
$bgrd_mobile = $section['background_image_mobile'];
if ( ! empty( $section['is_active'] ) ) { ?>
<section class="section-fullwidth section-image-hero-content">
<div class="row align-right align-middle">
<div class="column large-10 medium-12 small-24">
<header class="section-heading">
<h2 class="section-heading-title"><?php echo esc_html( $section_title ); ?></h2>
<?php if ( ! empty( $short_desc ) ) { ?>
<div class="section-heading-content">
<p><?php echo esc_html( $short_desc ); ?></p>
</div>
<?php } ?>
<?php acf_link( $cta_primary ); ?>
</header>
</div>
</div>
</section>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment