【问题标题】:Moving Magento Advanced Search Link From Footer To Beneath Search Bar将 Magento 高级搜索链接从页脚移动到搜索栏下方
【发布时间】:2012-09-11 15:23:42
【问题描述】:
我正在尝试从搜索栏正下方的页脚链接中移动 magentos 高级搜索链接。
我知道链接的来源在 layout/catalogsearch.xml 下
引用 name="footer_links" 并出现在页脚中,因为 getChildHtml('footer_links') in footer.phtml
而且我知道搜索栏源自 template/catalogsearch/form.mini.phtml,并通过 catalogsearch.xml 出现在参考名称 =“top.menu”下
关于如何在此处继续的任何想法?
【问题讨论】:
标签:
magento
advanced-search
【解决方案1】:
感谢您的快速回答!
但这并不是我想要的,因为它会在搜索栏下方显示整个页脚链接块。
不过还是感谢您向我展示了您使用的方法!
无论如何,我自己想出了一个解决方案:
我修改了catalogsearch.xml:
<default>
<reference name="top.menu">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
<!-- add a new reference to top.search including my new adv.search block -->
<reference name="top.search">
<block type="page/template_links" name="adv.search" as="adv.search" >
<action method="addLink" translate="label title" module="catalogsearch">
<label>Advanced Search</label>
<url helper="catalogsearch/getAdvancedSearchUrl" />
<title>Advanced Search</title>
</action>
</block>
</reference>
<!-- the reference to the footer i commented out as its not longer needed; it includes advanced search and popular search terms-->
</default>
在 form.mini.phtml 中我添加了一个新的 div 调用 adv.search:
</script>
<div class="adv-search"> <?php echo $this->getChildHtml('adv.search') ?> </div>
</div>
最后,在 styles.css 中,我添加了一些代码来控制该 div 的外观:
.adv-search {width:100px; height:15px; margin-top:24px; margin-left: 120px;}
.adv-search a { color:#fff; font-weight:bold; }
非常欢迎任何其他建议
干杯!
【解决方案2】:
为了让它工作,你必须:
1) 更新您的 app/design/frontend/[yourtheme]/default/layout/local.xml 文件
2) 调用 app/design/frontend/[yourtheme]/default/template/page/html/header.phtml 中的新块 - 这是必需的,因为 header.phtml 不是“core/text_list”块类型,它自动渲染其嵌套块。所以我们必须明确告诉 Magento 渲染那些子块
你的 app/design/frontend/[yourtheme]/default/layout/local.xml 应该包含这个:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<!-- Insert cms links. No need to use <action method="insert"> as this block is not used elsewhere in layout -->
<block type="cms/block" name="top_links_cms" as="top_links_cms" before="top_links_other">
<action method="setBlockId"><block_id>footer_links</block_id></action>
</block>
<!-- Insert former footer links. -->
<action method="insert">
<!-- We must keep block name "footer_links" as it is used as a reference for adding links by other modules -->
<blockName>footer_links</blockName>
<!-- Name of the block we want to have as sibling (in order to get its position and place our block after it. See next node <after> -->
<siblingName>topSearch</siblingName>
<!-- $after param from Mage_Core_Block_Abstract::insert() is a boolean type, so its value in the XML node is [empty], 0 or 1 -->
<after>1</after>
<alias>top_links_other</alias>
</action>
</reference>
<reference name="footer">
<action method="unsetChild"><name>footer_links</name></action>
<action method="unsetChild"><name>cms_footer_links</name></action>
</reference>
</default>
</layout>
这是一个更新的 header.phtml,您可以从中获取灵感,用于您的 app/design/frontend/[yourtheme]/default/template/page/html/header.phtml 文件:
<div class="header-container">
<div class="header">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
<?php else:?>
<a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
<?php endif?>
<div class="quick-access">
<?php echo $this->getChildHtml('topSearch') ?>
<?php
/**
* Add other top links (footer and cms links)
*/
?>
<?php echo $this->getChildHtml('top_links_cms') ?>
<?php echo $this->getChildHtml('top_links_other') ?>
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
</div>
</div>
<?php echo $this->getChildHtml('topMenu') ?>