【发布时间】:2021-09-05 21:53:12
【问题描述】:
使用内置的 WordPress 搜索表单:
<form role="search" method="get" class="search-form">
<?php
if ( function_exists( 'woocommerce_product_search' ) ) {
echo woocommerce_product_search( array( 'limit' => 40 ) );
}
?>
<div class="col-lg-4 col-lg-offset-4">
<div class="input-group">
<input type='textbox' maxlength="8" id="item-search" name="s" class="form-control form-inline" value="<?php the_search_query();?>" placeholder="Enter your postcode e.g. SW1Y 4LG"/>
<span class="input-group-btn">
<button class="item-search-btn">search</button>
</span>
</div>
</div>
</form>
我已经调用它出现在我的主页上(index.php):
<?php get_search_form(); ?>
我想添加一个if语句来显示:
<div id="postcode-no" class="col-lg-4 col-lg-offset-4">
Unfortunately this is incorrect.
</div>
所以我在 index.php 文件中添加了:
<?php if (input-text=='SW12') { ?>
<div id="postcode-no" class="col-lg-4 col-lg-offset-4">
Unfortunately this is incorrect.
</div>
<?php } else if (input-text=='SW15'){ ?>
<div id="postcode-no2" class="col-lg-4 col-lg-offset-4">
Correct.
</div>
<?php } ?>
但它不起作用。我对 PHP 相当陌生。我做错了什么?
【问题讨论】:
-
您可以使用 $input-text 作为 var 而不是 input-text 并首先打印 $input-text 以便您知道将输出什么。并使用 else 语句更好地理解
-
哦,好吧,我明白你的意思了。谢谢你。你对代码有答案吗? @mollie
-
请查看以下代码
-
绝对精彩!谢谢@mollie