【发布时间】:2018-08-13 20:32:41
【问题描述】:
我正在使用ACF plugin for WordPress。
使用灵活内容字段,管理员可以添加名为“复制”的布局。
在此布局中,他们可以选择“网格类型”(四分之一、三分之一、一半、完整)。以下是它在 ACF 中的外观:
这是它在我的模板文件中的外观:
<?php
// Begin layout builder
if( have_rows('layout_builder') ):
while ( have_rows('layout_builder') ) : the_row();
?>
<?php
// Begin layout - Copy
if( get_row_layout() == 'copy' ):
// Begin repeater
if( have_rows('copy') ):
// Grid
echo '<div class="grid-wrap">';
while ( have_rows('copy') ) : the_row();
?>
<div class="<?php
if ( get_sub_field('grid_type') == 'quarter' ) {
echo 'quarter';
}
if ( get_sub_field('grid_type') == 'third' ) {
echo 'third';
}
if ( get_sub_field('grid_type') == 'half' ) {
echo 'half';
}
if ( get_sub_field('grid_type') == 'full' ) {
echo 'full';
}
?>">
<?= get_sub_field('copy'); ?>
</div>
<?php
// End repeater
endwhile;
// End grid
echo '</div>';
endif;
// End layout
endif;
?>
<?php // End layout builder
endwhile;
endif;
?>
我期待grid_type 字段在前端吐出一个类,但它是空的。
当我使用<?php var_dump( get_sub_field('grid_type') == 'half' ); ?> 测试该字段时,它返回bool(false)。
我在这里做错了什么?
【问题讨论】:
标签: wordpress advanced-custom-fields