Created
April 24, 2019 19:05
-
-
Save acobster/021da616f55c4fa1f49c94e57cf3f0ba to your computer and use it in GitHub Desktop.
ACF Content Sections demo code
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 | |
/** | |
* Author: Coby Tamayo | |
*/ | |
use MyProject\Post\Page; | |
$page = new Page(); | |
// Get common/site-wide data | |
$data = $site->get_context_with_post($page); | |
// Get the raw content_layouts data, formatted and filtered | |
$data['content_layouts'] = array_map(function(array $section) : array { | |
if ($section['pattern'] !== 'signup-form') { | |
unset($section['signup_form']); | |
} | |
if ($section['pattern'] !== 'accordion') { | |
unset($section['accordion']); | |
} | |
return $section; | |
}, $page->get_field('content_layouts') ?: []); | |
// Render the default view | |
Timber::render( 'page-content-layouts.twig'], $data ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment