2014-08-27 127 views
-11

我需要一個if語句來創建包裝錨定鏈接,如果getBlockLink存在。到目前爲止所有嘗試都失敗。那裏的任何PHP嚮導能否爲我提供解決方案?編寫IF語句

<div class="<?php echo $this->getSize(); ?>"> 
<a href="<?php echo $this->getBlockLink(); ?>"> 
    <span class="grid grid--full"> 
     <span class="grid__item <?php echo $this->getTextPosition() . ' ' . $this->getTextWidth(); ?>"> 
      <?php echo $this->getBlockFormattedContent(); ?> 
     </span> 
     <img src="<?php echo $this->getImage(); ?>"> 
    </span> 
</a> 
</div> 
+0

需要其他比,如果給我一個真正的問題。檢查http://php.net/manual/en/control-structures.if.php上的示例 – 2014-08-27 14:50:56

回答

0

像這樣的東西應該工作:

<div class="<?php echo $this->getSize(); ?>"> 
    <?php if (!empty($this->getBlockLink())) : ?> 
    <a href="<?php echo $this->getBlockLink(); ?>"> 
    <?php endif; ?> 
    <span class="grid grid--full"> 
    <span class="grid__item <?php echo $this->getTextPosition() . ' ' . $this->getTextWidth(); ?>"> 
     <?php echo $this->getBlockFormattedContent(); ?> 
    </span> 
    <img src="<?php echo $this->getImage(); ?>"> 
    </span> 
    <?php if (!empty($this->getBlockLink())) : ?> 
    </a> 
    <?php endif; ?> 
</div> 
-2

這似乎是工作

<div class="<?php echo $this->getSize(); ?>"> 
<?php if($this->getBlockLink()): ?> 
    <a href="<?php echo $this->getBlockLink(); ?>"> 
<?php endif; ?> 
    <span class="grid grid--full"> 
     <span class="block_content grid__item <?php echo $this->getTextPosition() . ' ' . $this->getTextWidth(); ?>"> 
      <?php echo $this->getBlockFormattedContent(); ?> 
     </span> 
     <img src="<?php echo $this->getImage(); ?>"> 
    </span> 
<?php if($this->getBlockLink()): ?> 
    </a> 
<?php endif; ?>