&media;=helper-6ren">
gpt4 book ai didi

Magento:将 Pinterest "Pin it"按钮添加到产品详细信息页面

转载 作者:行者123 更新时间:2023-12-02 15:11:22 26 4
gpt4 key购买 nike

我正在尝试添加 "Pin it" button from Pinterest到我们网站的产品详细信息页面。

到目前为止我已经尝试过:

<a href="http://pinterest.com/pin/create/button/?url=<?php echo trim(Mage::registry('current_product')->getProductUrl()) ?>&media;=<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(265) ?>&description;=<?php echo Mage::registry('current_product')->getName(); ?>" class="pin-it-button" count-layout="none">Pin It</a>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>

<a href="http://pinterest.com/pin/create/button/?url=<?php echo trim(Mage::registry(\'current_product\')->getProductUrl()) ?>&media;=<?php echo Mage::helper('catalog/image')->init(Mage::registry('current_product'), 'small_image')->resize(900,900);?>&description;=<?php echo Mage::registry('current_product')->getName(); ?>" class="pin-it-button" count-layout="none">Pin It</a>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>

通过其中任何一个,我都可以获取产品的 URL 和产品名称,但无法获取产品的图像。因此该帖子不起作用(它需要所有 3 个项目才能起作用:URL、媒体和说明)

当我尝试这个时:

<a href="http://pinterest.com/pin/create/button/?url=http://eberjey.com&media;=<?php echo Mage::helper('catalog/image')->init(Mage::registry('current_product'), 'small_image')->resize(900,900);?>&description;=<?php echo Mage::registry('current_product')->getName(); ?>" class="pin-it-button" count-layout="none">Pin It</a>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>

我可以发布产品的图片,但 URL 不是动态的(我只是使用网站的绝对 URL)。

关于如何在我的产品详细信息页面中实现此按钮有什​​么想法吗?

最佳答案

这里的大多数答案都不会 urlencode() 为 pinterest 链接生成的查询字符串,所以我有点惊讶他们一直在工作 - 我的方法是 Andrew 的变体,它使用 http_build_query() 来为我做这个。

以下代码放在 template/catalog/product/view.phtml 中时可以工作:

<!--START PIN BUTTON-->
<?php
$_pinlink['url'] = $_product->getProductUrl();
$_pinlink['media'] = $this->helper('catalog/image')->init($_product, 'image')->__toString() ;
$_pinlink['description'] = $_helper->productAttribute($_product, $_product->getName(), 'name') . " - " . strip_tags($_product->getDescription());
?>
<a href="http://pinterest.com/pin/create/button/?<?php echo http_build_query($_pinlink) ?>" class="pin-it-button" count-layout="horizontal"></a>
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
<!--END PIN BUTTON-->

我还注意到 Pinterest 从发布的描述中删除了所有 html 标签,因此传递它们似乎没有多大意义 - 因此在描述中删除了标签。

关于Magento:将 Pinterest "Pin it"按钮添加到产品详细信息页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9035291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com