如果变量不为空,我想显示一些 html 代码,否则我什么都不显示。
我试过这段代码但不起作用:
<?php
$web = the_field('website');
if (isset($web)) {
?>
<span class="field-label">Website: </span><a href="http://<?php the_field('website'); ?>" target="_blank"><?php the_field('website'); ?></a>
<?php
} else {
echo "Niente";
}
?>
最佳答案
if (!empty($web)) {
?>
<span class="field-label">Website: </span><a href="http://<?php the_field('website'); ?>" target="_blank"><?php the_field('website'); ?></a>
<?php
} else { echo "Niente";}
关于PHP - 如果变量不为空,则回显一些 html 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9592855/