Php WordPress ACF灵活内容-在一个页面上多次使用布局块可复制内容
我有一个“灵活内容”领域,称为辅导和灵活部分。在这里,我有一个名为flex_coaching_details的“布局” 我希望能够在一个页面的不同位置多次使用该布局。所以在页面编辑器中,我添加了6次这个布局块 它正在输出6个块,但重复了6次,如下所示: 标题一标题一标题一标题一标题一标题一标题一标题一标题一 标题二标题二标题二标题二标题二标题二标题二标题二标题二 等等,直到第六名 有人能解释一下我哪里出了错,因为我不能完全理解这一点。我认为这与我的循环有关,但无论我尝试什么都不起作用 Flex布局页面模板循环-在这里,我提取保存在自己的.php文件中的所有布局文件:Php WordPress ACF灵活内容-在一个页面上多次使用布局块可复制内容,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我有一个“灵活内容”领域,称为辅导和灵活部分。在这里,我有一个名为flex_coaching_details的“布局” 我希望能够在一个页面的不同位置多次使用该布局。所以在页面编辑器中,我添加了6次这个布局块 它正在输出6个块,但重复了6次,如下所示: 标题一标题一标题一标题一标题一标题一标题一标题一标题一 标题二标题二标题二标题二标题二标题二标题二标题二标题二 等等,直到第六名 有人能解释一下我哪里出了错,因为我不能完全理解这一点。我认为这与我的循环有关,但无论我尝试什么都不起作用 Flex布
<?php
if( have_rows('coaching_flex_sections') ):
$sections = get_field( 'coaching_flex_sections' );
?>
<div class="coaching flex-sections">
<?php
while( have_rows('coaching_flex_sections') ): the_row();
// while( have_posts() ): the_post();
// Loop through flexible fields and load the respective file for each.
foreach( $sections as $i => $section ) {
$part = get_stylesheet_directory() . '/_template-parts/flex-layout/sections/' . $section['acf_fc_layout'] . '.php';
if ( file_exists( $part ) ) {
include( $part );
} else {
echo '<!-- Error: No such flexible field type "'. esc_html($section['acf_fc_layout']) .' at '. esc_html($part) .'" -->';
}
}
// endwhile;
endwhile;
?>
</div>
<?php endif; ?>
<?php
if ( !isset($section) ) die('Must be accessed through flex-layout.php');
// Fields used by this section with default values
$f = shortcode_atts(array(
'content_appearance' => null,
'content' => null,
), $section, 'custom-layout');
// Extra classes to use on the container
$classes = array();
$classes[] = 'appearance-' . $f['content_appearance'];
// Render the section
aa_flex_layout_section_start($section, $i, $classes);
?>
<?php if( get_row_layout() == 'flex_coaching_details' ): ?>
<!-- flex section content start -->
<?php $coaching_details_subheading = get_sub_field('flex_coaching_details_subheading'); ?>
<?= ($coaching_details_subheading)? '<h2 class="heading">' . $coaching_details_subheading . '</h2>' : ''; ?>
<!-- flex section content end -->
<?php endif; ?>
<?php
aa_flex_layout_section_end();
布局模板文件示例:
<?php
if( have_rows('coaching_flex_sections') ):
$sections = get_field( 'coaching_flex_sections' );
?>
<div class="coaching flex-sections">
<?php
while( have_rows('coaching_flex_sections') ): the_row();
// while( have_posts() ): the_post();
// Loop through flexible fields and load the respective file for each.
foreach( $sections as $i => $section ) {
$part = get_stylesheet_directory() . '/_template-parts/flex-layout/sections/' . $section['acf_fc_layout'] . '.php';
if ( file_exists( $part ) ) {
include( $part );
} else {
echo '<!-- Error: No such flexible field type "'. esc_html($section['acf_fc_layout']) .' at '. esc_html($part) .'" -->';
}
}
// endwhile;
endwhile;
?>
</div>
<?php endif; ?>
<?php
if ( !isset($section) ) die('Must be accessed through flex-layout.php');
// Fields used by this section with default values
$f = shortcode_atts(array(
'content_appearance' => null,
'content' => null,
), $section, 'custom-layout');
// Extra classes to use on the container
$classes = array();
$classes[] = 'appearance-' . $f['content_appearance'];
// Render the section
aa_flex_layout_section_start($section, $i, $classes);
?>
<?php if( get_row_layout() == 'flex_coaching_details' ): ?>
<!-- flex section content start -->
<?php $coaching_details_subheading = get_sub_field('flex_coaching_details_subheading'); ?>
<?= ($coaching_details_subheading)? '<h2 class="heading">' . $coaching_details_subheading . '</h2>' : ''; ?>
<!-- flex section content end -->
<?php endif; ?>
<?php
aa_flex_layout_section_end();