我正在努力制作一个if语句,其中如果变量值(页面标题)等于"loan",则隐藏字段div,但如果变量等于任何其他值,则显示div。
<?php
if(!empty($product['custom_fields'][1]['value'])){ ?>
<div class="content-2">
<p><strong><?= $product['custom_fields'][1]['field']?></strong>
<br /><?= $product['custom_fields'][1]['value']?></p>
</div>
<?php }
?>
我创建了以下代码来显示隐藏的div(在"借用"页面上),但似乎无法成功地将该代码合并到上述自定义字段变量的 if 语句中。
<?php
if(false !== stripos ($product_list_data['name'], 'loan')){
echo "<div class='content-bottom'><p><strong>" . $product['custom_fields'][1]['field'] . "</strong>
<br />" . $product['custom_fields'][1]['value'] . "</p></div>";
}
?>
任何帮助将不胜感激。
$display = 'block';
if (strpos($product_list_data['name'], 'loan') !== false) {
$display = 'none';
}
<div class="content-2" style="display:<?php echo $display; ?>;">
<p><strong><?= $product['custom_fields'][1]['field']?></strong>
<br /><?= $product['custom_fields'][1]['value']?></p>
</div>