我使用ACF Pro灵活的内容字段构建了一个简单的页面生成器。我希望用户能够使用单选按钮选择器为部分选择背景颜色。我已经设置了ACF字段,但我想在模板中选择值,并在div中回显一个类名,然后用CSS设置样式。
但我无法显示类名,这是我目前所拥有的:
if( get_field(\'background\', $post->ID) == \'white\' ):
$background = \'white\';
elseif ( get_field(\'background\', $post->ID) == \'light_grey\' ):
$background = \'light-grey\';
elseif( get_field(\'background\', $post->ID) == \'dark_grey\' ):
$background = \'dark-grey\';
else:
$background = \'\';
endif;
目前根本没有打印出来。此代码位于一个由我的主模板调用的文件中,该文件包含不同布局的代码。Ok修订代码:
if( get_row_layout() == \'full_width_col\' ):
$bg = get_sub_field(\'row_background\');
if( $bg ) {
$background = $bg[\'value\'];
} else {
$background =\'\';
} ?>
<div id="row-wrap-<?php echo $row;?>" class="<?php echo $background; ?> row-wrapper full-width clear">
<div id="row-<?php echo $row;?>" class="row">
<?php get_template_part(\'template-parts/acf/layout\', \'full-width-col\'); ?>
</div>
</div>
<?php endif; ?>