【问题标题】:Move the Search Box in Magento into Main Page将 Magento 中的搜索框移至主页
【发布时间】:2014-08-06 22:46:22
【问题描述】:

我正在尝试将搜索框移到我的主页中。具体来说,在我的“col-main”部分(主要部分)的开头。我已经用谷歌搜索了这个问题,并且已经尝试了几个小时,而且真的很挣扎..

我从我的“default/modern/layout/catalogsearch.xml”页面复制了这个:

<default>
    <reference name="top.bar">
        <block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
    </reference>
</default>

并将其粘贴到我的“默认/现代/布局/page.xml”页面中,位于“页眉”下方和“左栏”之前。

然后我进入“default/modern/template/page/3columns.phtml”并粘贴:

<?php echo $this->getChildHtml(‘topSearch’) ?>

在本节中:

<div class="col-main">
        <?php echo $this->getChildHtml(‘topSearch’) ?>
                    <?php echo $this->getChildHtml('global_messages') ?>
                    <?php echo $this->getChildHtml('content') ?>
                </div>

我什么也得不到。我究竟做错了什么?

【问题讨论】:

  • 如果你去掉引用的top.bar,它工作吗?
  • 很抱歉回复晚了。不幸的是,这并没有什么区别。

标签: magento search magento-1.7


【解决方案1】:

首先你需要创建或更新你的 local.xml 文件

您需要将块添加到正确的部分。

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <reference name="root">
            <block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
        </reference>
    </default>
</layout>

然后使用你当前使用的方式调用它。

<?php echo $this->getChildHtml(‘topSearch’) ?>

您所做的唯一问题是您引用了 top.bar 的位置。当您按照我介绍的方式引用它时,您现在可以访问网站上任何页面上的搜索。

【讨论】:

  • 抱歉我的回复晚了。我在任何地方都找不到“local.xml”文件,所以我创建了一个文件并将其放置在“默认/现代/布局/”中,与您在上面粘贴的内容完全相同,但不幸的是,这仍然不起作用。还有其他想法吗?
  • 我忘了我之前对此做了更长更详细的解释。确保检查文件路径。因为如果某些内容被覆盖,这些更改都不会出现。转到此链接并在此处查看我的答案。我做了一步一步的教学帖子。 link
【解决方案2】:

我只是通过调整我的 CSS 来做到这一点。可能不是最理想的方式,但至少它似乎有效。

【讨论】:

  • 你能详细说明一下吗.. 有空的时候.. ?
  • 我收回了。我通过将其添加到我的 css 来做到这一点: .top-bar { line-height:21px;浮动:对;宽度:680px;填充顶部:61px; padding-right: 12px;填充左:12px;边距底部:-61px; } 但现在我无法点击任何链接 :(
【解决方案3】:

您应该将块移动到内容;

top.bar取消设置子块:

<reference name="top.bar">
    <action method="unsetChild"><name>top.search</name></action>
<reference>

添加到content:

<reference name="content">
    <action method="insert"><name>top.search</name></action>
</reference>

【讨论】:

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