Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento 2中添加顶部链接

在Magento 2中添加顶部链接意味着在页面顶部显示一些有用的链接。以下是 CMS块,其中包括客户的一些个人信息,如我的帐户,我的心愿单,登录或您需要的任何内容。单击顶部链接并将用户重定向到包含更多特定信息的 CMS页面。创建顶部链接也可以推动他们的愿望,鼓励客户购买越来越多。

例如,在顶部菜单上,“我的心愿单”链接将保存并将其直接引导至他们感兴趣的产品列表,而无需结帐。

如果您正在搜索如何在Magento 2商店中添加顶部链接,本主题将根据您的需求帮助您完成所有顶部链接。

  • 第1步:添加/修改default.xml文件
  • 第2步:添加Link.php文件
  • 第3步:刷新缓存并测试您的Top链接结果

第1步:添加/修改default.xml文件

找到路径app/code/Mageplaza/HelloWorld/view/frontend/layout,然后default.xml通过以下方式添加/修改文件:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
     <referenceBlock name="header.links">
         <block class="Mageplaza\HelloWorld\Block\Link" name="add-new-header-link">
             <arguments>
     <argument name="label" xsi:type="string" translate="true">New Link</argument>
     <argument name="path" xsi:type="string" translate="true">new-link</argument>
     </arguments>
         </block>
     </referenceBlock>
</body>

第2步:添加Link.php文件

继续路径app/code/Mageplaza/HelloWorld/Block,您将添加link.php文件:

<?php
 
namespace Mageplaza\HelloWorld\Block;
 
class Link extends \Magento\Framework\View\Element\Html\Link
{
/**
* Render block HTML.
*
* @return string
*/
protected function _toHtml()
    {
     if (false != $this->getTemplate()) {
     return parent::_toHtml();
     }
     return '<li><a ' . $this->getLinkAttributes() . ' >' . $this->escapeHtml($this->getLabel()) . '</a></li>';
    }
}

如上所述清除缓存,当您需要将顶部链接添加为Magento 2商店中客户体验的顶级菜单时,您会感觉很舒服。关注并享受它!

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论