如果为空,则使用PHP隐藏自定义字段周围的HTML

时间:2016-02-11 02:50:50

标签: php html wordpress

如果我的自定义字段在Wordpress中为空,我试图隐藏所有的HTML

我用这个:

 import java.util.Scanner;

 public class Assignment3 {

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    System.out.println("Welcome to the Calculator!");
    System.out.println("Enter the first operand:");
    double firstOperand = scan.nextDouble();
    System.out.println("Enter the second operand:");
    double secondOperand = scan.nextDouble();
    System.out.println("Operations are:");
    System.out.println("ADD or  + for addition");
    System.out.println("SUBTRACT or - for subraction");
    System.out.println("MULTIPLY or * for multiplication");
    System.out.println("DIVIDE or / for division");
    System.out.println("Enter your selection:");
    String selection = scan.next();
    double ADD = (firstOperand + secondOperand);
    double SUBTRACT = (firstOperand - secondOperand);
    double MULTIPLY = (firstOperand * secondOperand);
    double DIVIDE = (firstOperand / secondOperand);

    if (selection.equals("+")) {
        System.out.println("The product is:" + ADD);
    }
    else if (selection.equals("-")) {
        System.out.println("The product is:" + SUBTRACT);
    }
    else if (selection.equals("*")) {
        System.out.println("The product is:" + MULTIPLY);
    }
    else if (selection.equals("/")) {
        System.out.println("The product is:" + DIVIDE);
    }
}
}

但只有1个自定义字段显示,任何想法为什么?我已经对它进行了相当多的调查,但无法弄清楚

2 个答案:

答案 0 :(得分:0)

假设您的字段是正确的(attribute_1value_1),那么代码的问题就是使用了错误的函数。

the_field 输出字段的内容。

if条件下,您需要使用返回字段内容的get_field

<?php if (get_field( 'attribute_1' ) && get_field( 'value_1' ) != "") { ?>
    <li style="line-height:2.25em;border-top:1px solid #dcdcdc;">
        <p style="font-size:15px;margin-bottom:0;"><?php the_field( 'attribute_1' ); ?> <span style="float:right;font-weight:600;font-family:'Varela Round';"><?php the_field( 'value_1' ); ?></span>
        </p>
    </li>
<?php } ?>

答案 1 :(得分:0)

由于您尚未提供有关上述方法的详细信息,因此您可以尝试这样的方法。

<?php
if(isset("myfield") && isset("myfield2")){
   echo "<input type=\"text\" id=\"customField1\"></input>";
} //repeat as necessary
?>

如果您将“myfield”视为来自不同页面的变量,那么您应该使用:

<?php //use $_GET if necessary
if(isset($_POST['myfield']) && isset($_POST['myfield2'])){
   echo "<input type=\"text\" id=\"customField1\"></input>";
} //repeat as necessary
?>