2017-01-06 19 views
-2

1つのタグに複数の「if」を使用する方法like <header>。 各divは、タブに関連しています。だから、私は各タブの条件を作り、表示したいと思う。1つのタグに複数の「if」を使用する方法

<?php \t \t \t \t \t 
 
$mainbox = get_field('on'); 
 
$guide = get_field('install_guide'); 
 
$required = get_field('required'); 
 
?> 
 
<section class="fieldset"> \t 
 
<header> 
 
<?php 
 
if (!empty($mainbox)){ 
 
<div class="download-taber active"> \t 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)){ \t 
 
<div class="install-guide-taber">tab3</div>} //// if true show this otherwise hide it 
 

 
elseif (!empty($required)){ 
 
\t \t <div class="system-required-taber">tab4</div>} //// if true show this otherwise hide it 
 
?> \t \t 
 
</header> 
 
</section> 
 
<?php endif; ?>

+0

条件タグを正しく閉じることはありません。それは、このようにする必要があり '<?phpの 場合(!空($のmainbox)){?>

\t tab1
////真のショーはこれがそうでなければそれを
tab2
' –

+0

を非表示にした場合、私はあなたがSOに必要とは思いませんPHPタグを閉じて開きます:-) – jeroen

+0

「elseif」は、条件が真である最初のタブだけが表示されるようにしてはいけません。 – pixelarbeit

答えて

0

だけで(テスト用の値を交換を容易にするためにそこにリスト声明):すべての変数がtrueに設定されている場合

<?php     
list($mainbox, $guide, $required) = [true, true, true]; 
?> 
<section class="fieldset"> 
    <header> 
    <?php if($mainbox) { ?> 
     <div class="download-taber active">tab1</div> 
     <div class="attr-taber">tab2</div> 
    <?php } ?> 
    <?php if($guide) { ?> 
     <div class="install-guide-taber">tab3</div> 
    <?php } ?> 
    <?php if($required) { ?> 
     <div class="system-required-taber">tab4</div> 
    <?php } ?>  
    </header> 
</section> 

、すべてのタブが表示されます。

0

PHPにhtmlを組み込むには、PHPのechoタグにhtmlコードを保存する必要があります。 これを試してください。

<?php     
    $mainbox = get_field('on'); 
    $guide = get_field('install_guide'); 
    $required = get_field('required'); 
    ?> 
    <section class="fieldset"> 
    <header> 
    <?php 
    if (!empty($mainbox)){ 
    echo "<div class='download-taber active'>tab1</div>"; //// if true show this otherwise hide it 
    echo "<div class='attr-taber'>tab2</div>";} //// if true show this otherwise hide it 

    elseif (!empty($guide)){  
    echo "<div class='install-guide-taber'>tab3</div>";} //// if true show this otherwise hide it 

    elseif (!empty($required)){ 
      echo "<div class='system-required-taber'>tab4</div>";} //// if true show this otherwise hide it 
    ?>  
    </header> 
    </section> 
    <?php endif; ?> 
関連する問題