【问题标题】:Magento 2 social share facebook messenger button?Magento 2 社交分享 facebook messenger 按钮?
【发布时间】:2022-01-19 13:26:17
【问题描述】:

如何在产品详细信息页面上为 facebook messenger 社交分享图标添加 url 链接? image

查看其他社交图标以供参考: https://magento.stackexchange.com/questions/226323/magento-2-social-share-buttons/226332

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: magento magento2 social


【解决方案1】:

在 catalog_product_view.xml 中添加此代码

<referenceContainer name="product.info.social">
    <block class="Magento\Catalog\Block\Product\View" name="product.info.socialmedia" template="Magento_Catalog::product/view/socialmedia.phtml"/>
</referenceContainer>

并在以下路径创建新的 phtml 文件:

app/design/frontend/Custom/theme/Magento_Catalog/templates/product/view/socialmedia.phtml

在其中添加以下代码。

<?php $_product = $block->getProduct(); ?>
<div class="social-media-icons">
    <!-- Facebook -->
    <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($_product->getProductUrl());?>&t=<?php echo urlencode($_product->getName())?>" onclick='javascript:window.open(this.href,"","width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes");return false' title="Share on facebook">
        <img src=""<?php echo $this->getViewFileUrl('Magento_Catalog::images/facebook-share.jpg'); ?>" alt="Facebook" width="12%">
    </a>
</div>

【讨论】:

    猜你喜欢
    • 2017-02-05
    • 2014-01-08
    • 1970-01-01
    • 2014-02-26
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多