【问题标题】:Writing an IF statement [closed]编写 IF 语句 [关闭]
【发布时间】:2014-10-21 05:19:14
【问题描述】:

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

【问题讨论】:

标签: php


【解决方案1】:

这样的事情应该可以工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 2017-09-05
      • 2012-12-30
      相关资源
      最近更新 更多