【问题标题】:magento top link changesmagento 顶部链接更改
【发布时间】:2017-06-13 17:01:17
【问题描述】:

我是 Magento 的新手。我在 Magento 中下载了一个主题并尝试更改顶部链接。我无法跟踪文件。如何更改 Magento 主题中的顶部链接。

【问题讨论】:

  • 看看前两天的话题,你会发现同样的问题。
  • 您要翻译链接标签?更改链接目标?添加新链接?删除现有链接?

标签: magento magento-1.5


【解决方案1】:

你需要编辑两个文件……

  1. app/design/frontend/default/default/layout/checkout.xml
  2. app/design/frontend/default/default/layout/customer.xml

您将在这些文件中看到链接被添加为name="top.links" - 只需使用注释标签将它们注释掉

希望这会对你有所帮助。

谢谢

【讨论】:

  • 我只是评论它们,但顶部的链接仍然显示在顶部。我不知道为什么以及如何编辑现有链接?我是 magento 的新手。所以请提供一点详细的帮助。谢谢
  • 如果你没有清理缓存,它仍然会显示。所以从 var->cache 文件夹中删除缓存。和浏览器也希望它现在可以工作
【解决方案2】:

你必须有点像夏洛克·福尔摩斯。 顶部链接的生成要归功于您可以在主题的布局文件 page.xml 中找到的块。然后在标题块中搜索块名称“topLinks”(在默认主题中,它是名称),您会找到<block type="page/template_links" name="top.links" as="topLinks"/>。这个块 topLinks 是由块类 Mage_Page_Block_Template_Links 生成的。此块中的重要方法是public function addLink(...),这意味着您必须在xml布局中搜索以下元素/标签<action method='addLink'>...</action>

客户模块的示例,在布局文件夹的文件customer.xml中:

    <reference name="top.links">
        <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
    </reference>

你应该找到不止一个使用这种方法的 xml 元素。 请注意,addLink 方法也可以通过编程方式调用(在 PHP 代码中),而不仅仅是在布局文件中。

希望对你有帮助

【讨论】:

    【解决方案3】:

    热门链接包括:登录/注销、我的帐户、我的愿望清单、我的购物车和结帐链接。 顶部链接和常规静态链接之间最重要的区别之一是,当您将产品添加到购物车或愿望清单时,顶部链接会自动记录添加的产品。 标题中默认 Magento 主题中的热门链接示例。 Magento 中热门链接的使用 在 Magento 中编辑标题链接很容易。首先我们必须调用块。

    <?php echo $this->getChildHtml('topLinks'); ?>
    

    在模板template/page/html/header.phtml中,但在page.xml中创建

    <block type="page/html_header" name="header" as="header">
        <block type="page/template_links" name="top.links" as="topLinks"/>
        <block type="core/text_list" name="top.menu" as="topMenu"/>
    </block>
    

    现在我们需要使用以下命令添加到该块的链接:

    <action method="addLink" translate="label title" >...</action>
    

    我们在以下 XML 文件中创建它:
    登录/注销,我的帐户 – customer.xml
    我的购物车和结帐 – checkout.xml
    我的愿望清单 – wishlist.xml

    需要注意的是,链接到我的购物车通过命令调用:

    <action method="addCartLink"></action>
    <action method="addCheckoutLink"></action>
    

    如果您想更改 Magento 顶部链接,您需要知道所有顶部链接都基于位于此处的模板:page/template/links.phtml。您可以在此处添加其他类或提交所需的更改。

    人们通常希望使用单独的链接。例如 Login/Logout 和 My Account 应该在左侧,My Wishlist、My Cart 和 Checkout 在右侧。

    类似于下面的示例 这很容易做到:

    打开 page.xml 并在那里创建另一个块,几乎与“topLinks”相同,但名称为“topLinksLeft”;

    <block type="page/html_header" name="header" as="header">
        <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
        <block type="core/text_list" name="top.menu" as="topMenu"/>
        <block type="page/template_links" name="top.links" as="topLinks"/>
        <block type="page/template_links" name="top.links.left" as="topLinksLeft"/>
    </block>
    

    在模板template/page/html/header.phtml中借助命令:

    <?php echo $this->getChildHtml('topLinksLeft'); ?>
    

    我们可以在适当的地方调用我们的块

    <div>
        <h1 id="logo" title="<?php echo $this->getLogoAlt() ?>" style="background-image:url(<?php echo $this->getLogoSrc() ?>);"><a href="<?php echo $this->getUrl('') ?>"><?php echo $this->getLogoAlt() ?></a></h1>
        <div><?php echo $this->getChildHtml('topLinksLeft') ?></div>
        <?php echo $this->getChildHtml('topLinks') ?>
        <?php echo $this->getChildHtml('topMenu') ?>
    </div>
    

    完成此操作后,打开 customer.xml,我们必须在其中更改负责登录/注销的块的名称,我的帐户。我们将其名称从“top.links.left”上的“top.links”更改为示例:

    <customer_logged_in>
        <reference name="top.links.left">
            <action method="addLink" translate="label title" module="customer">
                <label>My Account</label>
                <url helper="customer/getAccountUrl"/>
                <title>My Account</title>
                <prepare/>
                <urlParams/>
                <position>10</position>
            </action>
        </reference>
        <reference name="top.links.left">
            <action method="addLink" translate="label title" module="customer">
                <label>Log Out</label>
                <url helper="customer/getLogoutUrl"/>
                <title>Log Out</title>
                <prepare/>
                <urlParams/>
                <position>100</position>
            </action>
        </reference>
    </customer_logged_in>
    

    我们还可以为左侧的链接分配其他模板(在某些情况下非常有用)为此我们只需复制模板“page/template/links.phtml”并将其命名为links_left.phtml。所以现在我们有两个模板“links.phtml”用于右侧,“links_left.phtml”用于左侧。现在我们需要做的就是连接它。对于连接,我们使用块 «topLinksLeft» page.xml 并将其更改为 links_left.phtml。

    <block type="page/html_header" name="header" as="header">
        <block type="page/template_links" name="top.links" as="topLinks"/>
        <block type="page/template_links" name="top.links.left" as="topLinksLeft" template="page/template/links_left.phtml"/>
    </block>
    

    现在您可以为左侧和右侧应用不同的样式和 HTML。

    哇,差点忘了“注册”按钮,它通常位于“登录/注销”按钮附近。也不用担心。正如您已经猜到的那样,我们从客户开始。如果我们想在顶部链接中添加“注册”按钮,我们接下来要做的 xml 文件:

    <customer_logged_out>
        <reference name="top.links">
            <action method="addLink" translate="label title" module="customer">
                <label>Log In</label>
                <url helper="customer/getLoginUrl"/>
                <title>Log In</title>
                <prepare/>
                <urlParams/>
                <position>100</position>
            </action>
            <action method="addLink" translate="label title" module="customer">
                <label>register</label>
                <url helper="customer/getRegisterUrl"/>
                <title>register</title>
                <prepare/>
                <urlParams/>
                <position>10</position>
            </action>
        </reference>
    </customer_logged_out>
    

    所以现在您可以更改 Magento 顶部链接:例如,在您的标题中添加注册按钮,或者如果您愿意,甚至可以从顶部链接中删除登录。

    【讨论】:

      【解决方案4】:

      请在主题文件夹下创建local.xml,然后尝试通过url键删除顶部链接。请将以下代码粘贴到 local.xml 中。

      <default>
        <reference name="top.links"> 
          <action method="removeLinkByUrl">
            <url helper="checkout/url/getCartUrl" />
          </action> 
        </reference>
      </default>
      

      谢谢。

      【讨论】:

        【解决方案5】:

        顶部链接主要来自 .phtml 文件,但我们向您推荐了删除此 .XML 文件的最佳方法。在 XML 文件中搜索“top.links”文本和此文本指定参考名称,以便您可以从 .XML 文件(布局文件)中删除所有链接

        例子:

        <reference name="top.links">
                <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
        </reference>

        【讨论】:

          【解决方案6】:
          app\design\frontend\{namespace}\{yourtheme}\template\page
          

          在这里你可以找到你的 header.phtml、footer.phtml 和 body 布局

          【讨论】:

            【解决方案7】:

            从 magento 管理面板启用开发者模式

            从管理员那里得到系统->配置

            然后从左侧边栏的最后一个菜单中选择您的当前配置范围: 和 ADVANCED->DEVELOPER->DEBUG->Template Path Hints to yes

            然后转到前端,它将显示所有模板路径 按照给定的模板路径并更改您想要的任何内容

            别忘了禁用开发者模式

            【讨论】:

              【解决方案8】:

              您可以通过编辑参考名称=“top.links”块来修改它 以下 .xml 文件

              1. app/design/frontend/Your_theme/default/layout/checkout.xml

              2. app/design/frontend/Your_theme/default/layout/customer.xml

              查看以下帖子

              有关信息,请访问此网址:-https://www.templatemonster.com/help/magento-how-to-edit-header-links-2.html#gref

              【讨论】:

                【解决方案9】:

                很难回答您的问题,因为某些主题倾向于移动文件并做一些古怪的事情。尝试切换模板提示,这将显示正在渲染的模板在文件系统中的位置。

                http://help.sweettoothrewards.com/article/434-how-do-i-turn-on-template-path-hints

                “布局 XML”可能是“Magento 方式”在该块中插入链接,而要引用的块将是 top.links。

                粗略的谷歌搜索产生了一篇有点过时但仍然相关的文章,关于做你想做的事。

                http://excellencemagentoblog.com/blog/2011/09/07/magento-add-top-links-in-magento/

                请注意如何扩展和修改主题以及基本的 Magento 主题。您最终可能会为下一个开发人员创建大量额外的工作。

                我鼓励您在进行许多修改之前研究 Magento 主题回滚系统。

                【讨论】:

                  【解决方案10】:

                  无需更改任何源代码。

                  第 1 步:登录管理面板。

                  第 2 步:从顶部导航转到目录 > 管理类别

                  第 3 步:点击“添加子类别”

                  第 4 步:转到“显示设置”选项卡,将“显示模式”选择框值设置为“仅静态块”(在 CMS > 静态块下创建静态块)

                  第 5 步:使用必填字段保存类别。

                  【讨论】:

                    【解决方案11】:

                    使用模板路径提示,您可以轻松找到您的模板路径文件。 登录到管理面板和下

                    • 系统 -> 配置
                    • 将“配置范围”更改为“默认商店视图”(或您希望在其上查看模板路径的任何商店视图)
                    • 在左侧菜单的高级下单击开发人员
                    • 单击“调试”以展开该部分
                    • 将“模板路径提示”更改为“是”
                    • 点击保存配置

                    现在,您只需刷新商店的前端一次,即可看到以红色显示的模板路径。此模板路径提示将让您知道哪个块负责显示特定部分。

                    完成编辑后不要忘记隐藏模板路径。

                    【讨论】:

                      【解决方案12】:

                      在这种情况下,模板提示是您最好的朋友。如果您使用的是终端,请运行:

                      n98-magerun.phar dev:template-hints
                      

                      然后选择您当前使用的商店视图并按 Enter。如果您对终端不太满意,也可以在管理员中激活它们:

                      System > Configuration > Developer > Template Path Hints 'YES'
                      

                      注意:确保您位于正确的“当前配置范围”。如有必要,您可以在左上角的下拉菜单中进行修改。

                      然后刷新前端,复制文件路径,搜索你的文件。宾果游戏。

                      【讨论】:

                        【解决方案13】:

                        不需要任何代码。

                        转到系统 - 配置 - 常规 - 设计 - 标题并更改“欢迎文本”

                        【讨论】:

                          【解决方案14】:

                          您可以在模板路径上并在此文件中进行相应更改:- 系统 > 配置 > 开发人员 > 模板路径提示“是” 你也将获得区块信息

                          【讨论】:

                            【解决方案15】:

                            如果您删除/更改特定链接而不是转到特定文件,例如如果您想更改我的帐户链接而不是转到 yourtheme->layout->customer.xml 如果不存在则转到 base->layout->customer.xml

                            找到&lt;reference name="top.links"&gt;删除/更新。

                            【讨论】:

                              【解决方案16】:

                              如果您想知道文件的位置,那么您可以使用 magento 默认模板路径提示功能。检查下面给出的 URL。

                              http://excellencemagentoblog.com/blog/2011/09/07/magento-template-path-hints-magento/

                              【讨论】:

                                【解决方案17】:

                                第一步:登录magento admin
                                第二步:进入目录
                                step3:去管理分类
                                第 4 步:它们是主题的顶部链接,然后您可以编辑该链接

                                【讨论】:

                                  猜你喜欢
                                  • 2014-11-13
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 2011-02-07
                                  相关资源
                                  最近更新 更多