【发布时间】:2017-05-21 06:15:54
【问题描述】:
如何在一个标签like <header> 中使用多个“if”。
每个div 都与一个选项卡相关。所以我想为每个选项卡设置一个条件,以便显示。
<?php
$mainbox = get_field('on');
$guide = get_field('install_guide');
$required = get_field('required');
?>
<section class="fieldset">
<header>
<?php
if (!empty($mainbox)){
<div class="download-taber active"> tab1</div> //// if true show this otherwise hide it
<div class="attr-taber">tab2</div>} //// if true show this otherwise hide it
elseif (!empty($guide)){
<div class="install-guide-taber">tab3</div>} //// if true show this otherwise hide it
elseif (!empty($required)){
<div class="system-required-taber">tab4</div>} //// if true show this otherwise hide it
?>
</header>
</section>
<?php endif; ?>
【问题讨论】:
-
您没有正确关闭您的条件标签。应该是这样的
<?php if (!empty($mainbox)){ ?> <div class="download-taber active"> tab1</div> //// if true show this otherwise hide it <div class="attr-taber">tab2</div> <?php } ?> -
我认为您不需要添加关闭和打开 php 标签 :-)
-
你不应该使用
elseif否则只会显示第一个条件为真的选项卡。
标签: php if-statement advanced-custom-fields