-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflexible-content-loop.php
36 lines (28 loc) · 1.08 KB
/
flexible-content-loop.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* Flexible Content Loop for ACF
*
* Use this file to display ACF flexible content layouts.
*
* Instructions:
* 1. Include in your template file using include(get_template_directory() . '/acf-flex-starter/flexible-content-loop.php');
* 2. Ensure your ACF flexible content field is named 'layouts' or modify have_rows('layouts') accordingly.
* 3. Add additional layout files in '/acf-flex-starter/layouts/' (e.g., 'your_custom_layout.php') for automatic inclusion.
*/
// Check if the flexible content field has rows of data
if (have_rows('layouts')):
// Slider counter (required for aria-control)
$slider_counter = 0;
// Loop through the rows of data
while (have_rows('layouts')): the_row();
// Get layout
$layout = get_row_layout();
// Increment the counter for each slider
if ($layout == 'slider') {
$slider_counter++;
set_query_var('slider_id', 'slider-' . $slider_counter);
}
// Include the layout file
get_template_part('acf-flex-starter/layouts/' . $layout);
endwhile;
endif;