{"id":678,"date":"2019-11-23T19:04:30","date_gmt":"2019-11-23T12:04:30","guid":{"rendered":"https:\/\/lab.wptips.dev\/?p=678"},"modified":"2020-06-21T09:49:46","modified_gmt":"2020-06-21T02:49:46","slug":"diy-page-builder-with-acf","status":"publish","type":"post","link":"https:\/\/pixelstudio.id\/blog\/diy-page-builder-with-acf\/","title":{"rendered":"Creating Page Builder with ACF Flexible Content"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p><strong>ACF<\/strong> (Advanced Custom Fields) is a plugin to create user-friendly custom fields. <a href=\"https:\/\/www.advancedcustomfields.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Visit their website<\/a> to learn more.<\/p><\/blockquote>\n\n\n\n<p>Not satisfied with Gutenberg? Want a fully custom page builder? See no further than Flexible Content which is part of <a href=\"https:\/\/www.advancedcustomfields.com\/pro\/\">ACF Pro<\/a> (we are not affiliated with them).<\/p>\n\n\n\n<p style=\"font-size:14px\"><strong>Psst!<\/strong> If you haven&#8217;t bought ACF Pro, do it before 2020 because they are grandfathering the Unlimited Lifetime plan.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Flexible Content?<\/h2>\n\n\n\n<p>It is a field type which act <strong>like a Repeater<\/strong> but you can have different fields in each row. Simply perfect for page builder.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"436\" src=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-preview.jpg\" alt=\"\" class=\"wp-image-800\" srcset=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-preview.jpg 750w, https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-preview-480x279.jpg 480w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption>A preview of ACF Flexible Content <\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to Create?<\/h2>\n\n\n\n<p>First add a new field and set its type to <strong>Flexible Content<\/strong>. In the expanded setting, you can create multiple layouts, each with its own set of fields:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"653\" src=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-create.jpg\" alt=\"\" class=\"wp-image-801\" srcset=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-create.jpg 750w, https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-create-480x418.jpg 480w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption>Creating a Flexible Content field<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">How to Render?<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>The guide below is for pure-PHP, <a href=\"\/flexible-content-in-timber\/\">read here<\/a> if you want to use Timber Library.<\/p><\/blockquote>\n\n\n\n<p>In your theme, create a new folder called <code>\/layouts<\/code> and create new files with exact name as your layout&#8217;s:<\/p>\n\n\n\n<pre title=\"\" class=\"wp-block-code\"><code class=\"\">...\nlayouts\/\n\u251c\u2500\u2500 free_content.php\n\u251c\u2500\u2500 testimonials.php\n\u251c\u2500\u2500 gallery.php\n\u251c\u2500\u2500 ...\n...<\/code><\/pre>\n\n\n\n<p>Then add the following snippets to your <code>page.php<\/code> or if you want to use this in Post, put it in <code>single.php<\/code>:<\/p>\n\n\n\n<pre title=\"page.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php if( have_rows('layouts') ):\n  while( have_rows('layouts') ): the_row();\n    \n    $layout_name = get_row_layout();\n    get_template_part( \"layouts\/$layout_name\" );\n\n  endwhile;\nendif; ?><\/code><\/pre>\n\n\n\n<p>After that, implement the layout file. Some examples:<\/p>\n\n\n\n<pre title=\"layouts\/free_content.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;section class=\"free-content-layout\">\n  &lt;h2>\n    &lt;?php echo get_sub_field( 'title' ); ?>\n  &lt;\/h2>\n  &lt;?php echo get_sub_field( 'content' ); ?>\n&lt;\/section><\/code><\/pre>\n\n\n\n<pre title=\"layouts\/gallery.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;section class=\"gallery-layout\">\n  &lt;h2>\n    &lt;?php echo get_sub_field( 'title' ); ?>\n  &lt;\/h2>\n  &lt;?php $images = get_sub_field( 'content' ); ?>\n  \n  &lt;div class=\"gallery-items\">\n    &lt;?php foreach( $images as $i ): ?>\n      \n      &lt;figure>\n        &lt;img src=\"&lt;?php echo $i['sizes']['thumbnail']; ?>\"\n          alt=\"&lt;?php echo $i['alt']; ?>\">\n      &lt;\/figure>\n  \n    &lt;?php endforeach; ?>\n  &lt;\/div>\n&lt;\/section><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Make the Fields Tidier (Optional)<\/h2>\n\n\n\n<p>Your group will look messy after having several layouts. First step to make them tidier is to split each layouts into its own group like pictured below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"556\" src=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-split.jpg\" alt=\"\" class=\"wp-image-802\" srcset=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-split.jpg 750w, https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-split-480x356.jpg 480w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption>Free Content group<br><strong>(*)<\/strong> Don&#8217;t forget to deactivate the group<\/figcaption><\/figure>\n\n\n\n<p>Then inside the Flexible Content, add a single <strong>Clone field<\/strong> linking to the splitted group:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"630\" src=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-clone.jpg\" alt=\"\" class=\"wp-image-803\" srcset=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-clone.jpg 750w, https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2019\/11\/acf-flex-clone-480x403.jpg 480w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption>Link the splitted group by using Clone field<\/figcaption><\/figure>\n\n\n\n<p>Now whenever you changed the splitted group, the one inside layout will be changed too.<\/p>\n\n\n\n<hr class=\"wp-block-separator is-style-dots\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Flexible Content is a powerful yet underused tool in ACF Pro arsenal. Personally I have used this on all my projects prior to Gutenberg release.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>If you have any question related to Flexible Content field, feel free to leave a comment below \ud83d\ude42<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Not satisfied with Gutenberg? Want a fully custom page builder? See no further than Flexible Content which is part of ACF Pro.<\/p>\n","protected":false},"author":1,"featured_media":752,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20,40,31],"class_list":["post-678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-acf","tag-acf","tag-html","tag-php"],"blocksy_meta":{"page_structure_type":"default","page_enable_vertical_spacing":"yes","has_hero_section":"default","hero_section":"type-1","hero_alignment1":"left","hero_alignment2":"center","hero_height":"230px","page_title_bg_type":"color","5063fa32f629466ae7d9355c1ced56e6":"","custom_hero_background":{"attachment_id":null},"parallax":{"desktop":false,"tablet":false,"mobile":false},"single_meta_elements":{"author":true,"date":true,"categories":true,"comments":true,"updated":false,"tags":false},"has_meta_label":"yes","single_meta_date_format":"M j, Y","page_excerpt_visibility":{"desktop":true,"tablet":true,"mobile":false},"pageTitleFont":{"family":"Default","variation":"n7","size":{"desktop":"32px","tablet":"30px","mobile":"25px"},"line-height":"1.3","letter-spacing":"0em","text-transform":"none","text-decoration":"none"},"pageTitleFontColor":{"default":{"color":"var(--paletteColor4)"}},"pageMetaFont":{"family":"Default","variation":"n6","size":{"desktop":"12px","tablet":"12px","mobile":"12px"},"line-height":"1.3","letter-spacing":"0em","text-transform":"uppercase","text-decoration":"none"},"pageMetaFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageExcerptFont":{"family":"Default","variation":"n5","size":"17px","line-height":"1.65","letter-spacing":"0em","text-transform":"none","text-decoration":"none"},"pageExcerptColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageTitleOverlay":{"default":{"color":"rgba(41, 51, 60, 0.2)"}},"pageTitleBackground":{"default":{"color":"#EDEFF2"}},"6132ae22a8470e887630e91d247ba688":"","dabbcc4ad0bc56676bb1edb1a855d3cf":"","52c2162393b275ecd0139bfcf5953646":"","a40ba259524ae83fd40ac9de1adfb042":"","b9a02e91075679182a70f2558914131d":"","8c57f672120777422d36dc3ed95ddb26":"","63d2aae7aa63b094f756d1f1875970de":"","3e3ef986bdcbbe3f2f78911698cf1826":"","date_format_source":"custom","af943fc31f0dc9caa49b6fbf9e839afb":"","d95518ef0aee7f72e2e42b9d947da4a8":"","e9300478a20b51138e007c4ebfebbc65":"","e9c389c0f9299cb4712870e966fe8c77":"","4481d24f9adb58dd0e63b586676d57ef":"","8252d716e57250a9450248072dd6a42c":"","b78d5818efdbd46397685f70d0843cb1":""},"_links":{"self":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts\/678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/comments?post=678"}],"version-history":[{"count":10,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts\/678\/revisions"}],"predecessor-version":[{"id":1654,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts\/678\/revisions\/1654"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/media\/752"}],"wp:attachment":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/media?parent=678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/categories?post=678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/tags?post=678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}