【发布时间】:2019-10-30 02:13:40
【问题描述】:
我想在中继器中选择复选框时更改类。我使用switch case 执行此操作,但我无法获得while 之外的支票簿值。如何正确地从while 中取出复选框数组?
ACF
$checkboxarray = get_field('sy_color');
代码:
<div class="loop solution-include-pages d-flex">
<?php
if (have_rows('support_you')) {
$checkboxarray = get_field('sy_color');
foreach ($checkboxarray as $value) {
switch ($value) {
case 'red':
$class = 'rose-c';
break;
case 'green':
$class = 'green-c';
break;
case 'blueberry':
$class = 'blueberry-c';
break;
}
while (have_rows('support_you')) {
the_row();
$sy_img = get_sub_field('sy_img');
$sol_img = wp_get_attachment_image_src( $sy_img, 'full', true );
$sy_header = get_sub_field('sy_header');
$sy_content = get_sub_field('sy_content');
$sy_link = get_sub_field('sy_link');
$sy_color = get_sub_field('sy_color');
?>
<div class="sol-item d-flex flex-direction">
<div class="sol-item-img">
<img src="<?php echo $sol_img[0];?>" class="img-responsive" alt="">
</div>
<div class="sol-content">
<div class="sol-content-header <?php echo $class; ?>">
<?php echo $sy_header; ?>
</div>
<div class="sol-content-text">
<?php echo $sy_content; ?>
</div>
<a href="<?php echo $sy_link;?>" class="bluberry-btn item-center">Learn more</a>
</div>
</div>
<?php
}
}
}
?>
</div>
Acf 支票选项:
【问题讨论】:
-
如果复选框在中继器内,则应使用
get_sub_field()而不是get_field()
标签: wordpress advanced-custom-fields