【发布时间】:2014-11-02 09:36:21
【问题描述】:
我不知道如何获取在转发器字段中输入的复选框的值。只有一种选择。基本上,如果用户勾选复选框,它应该输出一个类。
在代码示例中,我还没有类中的值,因为我只是想让它打印一些东西!参数。
感谢您的任何帮助,我很感激!
<?php if( have_rows( 'milestone_module' ) ) : ?>
<section id="tao-timeline">
<?php
while( have_rows( 'milestone_module' ) ) : the_row();
// Vars
$milestone_module_date = get_sub_field( 'milestone_module_date' );
$milestone_module_copy = get_sub_field( 'milestone_module_copy' );
$field = get_field_object('milestone_long_date');
$value = get_field('milestone_long_date');
$label = $field['choices'][ $value ];
?>
<div class="tao-timeline-block">
<?php if( $milestone_module_date ) : ?>
<span class="tao-timeline-date">
<?php echo $label; ?>
<?php echo $milestone_module_date; ?>
</span><!--/.tao-timeline-date-->
<?php endif; ?>
<?php if( $milestone_module_copy ) : ?>
<div class="tao-timeline-content">
<?php echo $milestone_module_copy; ?>
</div><!--/.tao-timeline-content-->
<?php endif; ?>
</div><!--/.tao-timeline-block-->
<?php endwhile; wp_reset_postdata(); ?>
</section><!--/#tao-timeline-->
<?php endif; ?>
更新了真/假的代码,仍然无法正常工作......
<?php if( have_rows( 'milestone_module' ) ) : ?>
<section id="tao-timeline">
<?php
while( have_rows( 'milestone_module' ) ) : the_row();
// Vars
$milestone_module_date = get_sub_field( 'milestone_module_date' );
$milestone_module_copy = get_sub_field( 'milestone_module_copy' );
?>
<div class="tao-timeline-block">
<?php if( get_field('milestone_long_date') ) { ?>
<span class="tao-timeline-date long-date">
<?php echo $milestone_module_date; ?>
</span><!--/.tao-timeline-date-->
<?php } else { ?>
<span class="tao-timeline-date">
<?php echo $milestone_module_date; ?>
</span><!--/.tao-timeline-date-->
<?php } ?>
<?php if( $milestone_module_copy ) : ?>
<div class="tao-timeline-content">
<?php echo $milestone_module_copy; ?>
</div><!--/.tao-timeline-content-->
<?php endif; ?>
</div><!--/.tao-timeline-block-->
<?php endwhile; wp_reset_postdata(); ?>
</section><!--/#tao-timeline-->
<?php endif; ?>
【问题讨论】:
-
是类在值中,还是勾选了是一个设定值?
-
如果选中该框,则设置一个值。如果未选中该框,则不会打印任何课程。该类将是 .long-date,如果他们不选中该框,则不会添加该类。
-
所以你的意思是它是一个真/假字段?见advancedcustomfields.com/resources/true-false
-
是的,这是真/假。也许我设置错了?
-
是的......你的东西被编码成一个复选框(它有一个选项)。真/假是不同的。它的行为类似于“if”语句。哪个字段是真/假,我也许可以帮助您重组。
标签: wordpress checkbox advanced-custom-fields