编写IF语句

时间:2014-08-27 14:47:18

标签: php

如果getBlockLink存在,我需要一个if语句来创建包装锚链接。到目前为止所有尝试都失败了。任何php向导都能为我提供解决方案吗?

<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>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:-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; ?>