Skip to content

Instantly share code, notes, and snippets.

@KreigD
Created April 20, 2023 19:05
Show Gist options
  • Select an option

  • Save KreigD/5f260ed800c7917ed225753a5ea2894e to your computer and use it in GitHub Desktop.

Select an option

Save KreigD/5f260ed800c7917ed225753a5ea2894e to your computer and use it in GitHub Desktop.

Revisions

  1. KreigD created this gist Apr 20, 2023.
    27 changes: 27 additions & 0 deletions content-flexible.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php
    /**
    * Partial template for ACF flexible content
    *
    * @package Understrap
    */

    // Exit if accessed directly.
    defined( 'ABSPATH' ) || exit;

    the_title( '<h1 class="entry-title d-none">', '</h1>' );

    // check for ACF flexible content data
    if ( have_rows( 'modules' ) ) {

    // loop through the select ACF flexible content layouts
    while( have_rows( 'modules' ) ) {
    the_row();

    // dispaly the matching flexible content partial
    get_template_part( 'modules/' . get_row_layout() );

    // Just add your row templates into a directory named `modules` in the root of your theme
    // Each row template shoud have a filename matching the ACF slug
    // (ex: three-columns.php for a field with slug `three-columns`)
    }
    }
    47 changes: 47 additions & 0 deletions template-flexible-content.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <?php
    /**
    * Template Name: Flexible Content
    *
    * Template for displaying ACF Flexible Content Modules
    *
    * @package Understrap
    */

    // Exit if accessed directly.
    defined( 'ABSPATH' ) || exit;

    get_header();

    ?>

    <div class="wrapper" id="page-wrapper">

    <div class="container-fluid" id="content" tabindex="-1">

    <div class="row">

    <main class="site-main" id="main">

    <?php
    while ( have_posts() ) {
    the_post();
    // Get the template part for looping through our flexible content fields
    get_template_part( 'loop-templates/content', 'flexible' );

    // If comments are open or we have at least one comment, load up the comment template.
    if ( comments_open() || get_comments_number() ) {
    comments_template();
    }
    }
    ?>

    </main><!-- #main -->

    </div><!-- .row -->

    </div><!-- #content -->

    </div><!-- #page-wrapper -->

    <?php
    get_footer();