ACF True / False字段,仅在设置为True时运行代码

时间:2019-03-20 14:10:25

标签: google-maps advanced-custom-fields

我正在使用ACF谷歌地图向客户提供投标简介位置的指示。

我使用的是ACF True / False字段,并且仅当该字段设置为TRUE时才想显示Google Maps地址链接。

<span class="font-weight-bold">
    <b>Compulsory Briefing:</b>
</span>

<?php the_field('compulsory_briefing') ?><br/>
<span class="font-weight-bold">
    <b>Address [Google Maps] <a class="directions" target="_blank" href="https://www.google.com/maps?saddr=My+Location&daddr=<?php $location = the_field('briefing_address'); echo $location['lat'] . ',' . $location['lng']; ?>"> <?php _e(' Get Directions','roots'); ?>
</a>

1 个答案:

答案 0 :(得分:0)

您需要将按钮包装在if语句中,以检查该值是否设置为true或false:

<span class="font-weight-bold">
    <b>Compulsory Briefing:</b>
</span>

<?php if( get_field('compulsory_briefing') ): ?>
    <span class="font-weight-bold">
        <b>Address [Google Maps] <a class="directions" target="_blank" href="https://www.google.com/maps?saddr=My+Location&daddr=<?php $location = the_field('briefing_address'); echo $location['lat'] . ',' . $location['lng']; ?>"> <?php _e(' Get Directions','roots'); ?></a>
    </span>
<?php endif;?>

这是如果您的True / False字段是“ combrory_briefing”,则情况并非如此。

有关ACF Click Here中True / False字段的更多信息。

相关问题