[英]How to Wrap A Condition Inside Another Condition in PHP
Can anyone please help me wrap the condition inside another condition in php.任何人都可以帮助我将条件包装在 php 中的另一个条件中。
I have this code #1 that I want to be inside code #2.我有这个代码 #1,我想在代码 #2 中。
Here's code #1这是代码#1
<?php if( get_field('highlights') ): ?>
<div class="overview">
<h3>Quick Overview</h3>
<?php the_field('highlights'); ?>
</div>
<?php endif; ?>
Here's code #2这是代码#2
<?php if(strstr($_SERVER['HTTP_REFERER'],'www.example.com'))
{
echo '**CODE #1 should be placed here**';
}
?>
Sorry, I don't haev any knowledge in PHP.抱歉,我对 PHP 没有任何了解。
Wrapping code 1 inside code 2将代码 1 包装在代码 2 中
After several trial and error, here's what I have to make it work.经过多次试验和错误,这就是我必须让它发挥作用的方法。 Please correct me if there's something wrong or to improve.如果有什么不对或需要改进的地方,请纠正我。
<?php if (strstr($_SERVER['HTTP_REFERER'], 'www.google.com')){ ?>
<?php if( get_field('highlights') ):?>
<div class="overview">
<h3>Quick Overview</h3>
<?php the_field('highlights'); ?>
</div>
<?php endif; ?>
<?php } ?>
This should work in theory.这在理论上应该有效。 Though I'm unsure what the highlights
field is for.虽然我不确定highlights
字段的用途。
<?php
if(strstr($_SERVER['HTTP_REFERER'],'www.example.com')){
if( get_field('highlights') ){ ?>
<div class="overview">
<h3>Quick Overview</h3>
<?php the_field('highlights'); ?>
</div>
<?php
}
}
?>
You may want to replace <?php the_field('highlights'); ?>
您可能想要替换<?php the_field('highlights'); ?>
<?php the_field('highlights'); ?>
with something like <?=highlight?>
and iterate through the highlights in a loop. <?php the_field('highlights'); ?>
使用类似<?=highlight?>
的内容,并在循环中遍历突出显示。 That depends on the situation though.不过这要视情况而定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.