如果在PHP中为空,则不显示

如果在PHP中为空,则不显示,php,joomla,Php,Joomla,我在Joomla文章中添加了额外的字段,如果有空字段,我不想显示新字段(和“li”): 由此 <ul> <li> <?php echo $this->item->direccion; ?> <a href="<?php echo $this->item->urlMap; ?>" target="<?php echo $this->item->targetMap; ?&

我在Joomla文章中添加了额外的字段,如果有空字段,我不想显示新字段(和“li”):

由此

<ul>
  <li>
      <?php echo $this->item->direccion; ?>  
      <a href="<?php echo  $this->item->urlMap; ?>" target="<?php echo $this->item->targetMap; ?>">Mapa</a>
   </li>
</ul>
对这样的事情:

 <ul>
   <li "if MOLA is empty not show this li">
      <?php echo $this->item->MOLA; ?>  
      <a href="<?php echo  $this->item->urlMap; ?>" target="<?php echo $this->item->targetMap; ?>">Map</a>
   </li>
 </ul>

您可以在
  • 之前使用
    if
    条件,并检查变量是否不是
    空的

     <ul>
       <?php if(!empty($this->item->MOLA)) { ?>      
       <li>
          <?php echo $this->item->MOLA; ?>  
          <a href="<?php echo  $this->item->urlMap; ?>" target="<?php echo $this->item->targetMap; ?>">Map</a>
       </li>
       <?php } ?> 
     </ul>
    

    ..
    它在你的第二个密码中给了我一个错误line@BizarriaesspumosaStudio对不起,输入错误,分号不在这里,fixed@BizarriaesspumosaStudio你能读懂错误吗?如果你连语法都不懂,就不要写php:先试试js…Weeee。。。完美的它起作用了。我学习很慢。。。抱歉…@bizarriaesspumosatudio我很高兴它能工作,别忘了接受答案,以帮助未来有类似问题的人!