【问题标题】:How to wrap links with <a> tags?如何用 <a> 标签包装链接?
【发布时间】:2013-05-23 07:19:19
【问题描述】:

在 Magento 中,我制作了属性字段。并插入 4 个链接:

http://www.first-link.com/
http://www.second-link.com/
http://www.third-link.com/
http://www.fourth-link.com/

<?php echo $_helper->productAttribute($_product, $_product->getLinks(), 'links') ?>

我显示这 4 个裸链接。

但我想用&lt;a&gt; 标记包装它们来制作这样的东西:

<a href="http://www.first-link.com/" target="_blank">Link 1 - description</a><br>
<a href="http://www.second-link.com/" target="_blank">Link 2 - description</a><br>
<a href="http://www.third-link.com/" target="_blank">Link 3 - description</a><br>
<a href="http://www.fourth-link.com/" target="_blank">Link 4 - description</a>

我在服务器上安装了 PHP 5.3。

【问题讨论】:

    标签: php html string magento


    【解决方案1】:

    我只是一起破解了一些东西,可能会更好地解决

    <?php 
    
    $links = $_helper->productAttribute($_product, $_product->getLinks(), 'links');
    $array = explode('http://',$links);
    
    foreach ($array as $link) {
     if (empty($link)) continue;
     echo "<a href='http://".$link."' target='_blank'>Link 1 - description</a><br>";
    }
    
    ?>
    

    【讨论】:

    • 顺便说一句,它确实有效。不过还是得为链接描述找点东西
    【解决方案2】:

    用于描述(或任何其他属性)

    $attributes = $_product->getAttributes();
    $description = $attributes['description']->getFrontend()->getValue($_product);
    echo $description;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      相关资源
      最近更新 更多