`
yanggaojiao
  • 浏览: 80148 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

在导航栏中或其他位置添加Home链接

阅读更多

本节不打算翻译,留给自己需要的时候Copy用

Add Home Link with functional active state to Menu Bar (Alternative Method)

Find the file called top.phtml in app/design/frontend/default/yourtheme/template/catalog/navigation/ and make the following change:

<div class="header-nav-container">
    <div class="header-nav">
        <h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
        <ul id="nav">
 
        <!-- ALTERNATIVE HOME BUTTON HACK -->
        <li class="home"><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home') ?></a></li>
        <!-- ALTERNATIVE HOME BUTTON HACK -->
 
        <?php foreach ($this->getStoreCategories() as $_category):?>
            <?php echo $this->drawItem($_category) ?>
        <?php endforeach ?>
        </ul>
    </div>
    <?php echo $this->getChildHtml('topLeftLinks') ?>
</div>

 

Add the following to the menu.css file in skin/frontend/default/yourtheme/css/. This example is for a CMS home page which uses cms-home class in its body tag.

body.cms-home #nav li.home a { color:#d96708; }

 

NOTE: The following comments refer to the following methods.


:::: TRIED THIS AND IT ADDS THE LINK, BUT THE ACTIVE STATE DOES NOT FUNCTION CORRECTLY ::::

Special Note to the person(s) responsible for this page. Myself and many others have attempted to use this code snippet to get the result explained with an active state, but have been unable to get the active state to work. The link does work as far as pointing to exsisting cms page or external pages, but the “active” state does not work at all. Page refreshes and all links adjust back to original state.

FOR HOME LINK ONLY ACTIVE STATE I use the following as it’s the simplist way to get the active state working correctly on the home link.

<div class="header-nav-container">
    <div class="header-nav">
        <h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
        <ul id="nav">
 
        <!-- WORKING ACTIVE STATE HOME BUTTON HACK -->
        <li class="home<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()):?> active<?php endif;?>"><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home') ?></a></li>
        <!-- WORKING ACTIVE STATE HOME BUTTON HACK -->
 
        <?php foreach ($this->getStoreCategories() as $_category):?>
            <?php echo $this->drawItem($_category) ?>
        <?php endforeach ?>
        </ul>
    </div>
    <?php echo $this->getChildHtml('topLeftLinks') ?>
</div>

 


For the Home link in the menu bar of the main template you can add some code to one of the template files.

Find the file called top.phtml in app/design/frontend/default/default/template/catalog/navigation/ and make the following change:

div class="header-nav-container">
    <div class="header-nav">
        <h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
        <ul id="nav">
 
        <!-- HOME BUTTON HACK -->
        <?php $_anyActive = false; foreach ($this->getStoreCategories() as $_category) { $_anyActive = $_anyActive || $this->isCategoryActive($_category); } ?>
        <li class="<?php echo !$_anyActive ? 'active' : '' ?>"><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home') ?></a></li>
        <!-- HOME BUTTON HACK -->
 
        <?php foreach ($this->getStoreCategories(10) as $_category):?>
            <?php echo $this->drawItem($_category) ?>
        <?php endforeach ?>
        </ul>
    </div>
    <?php echo $this->getChildHtml('topLeftLinks') ?>
</div>

 

:x:x:x: Tried several on this page. The one directly above worked best. I modified it a little bit to contain a link title. Just paste

<li class="home<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()):?> active<?php endif;?>"><a href="<?php echo $this->getUrl('')?>" title="Home">Home</a></li>

 

just before

<?php echo $_menu; ?>

 

if you’re using the default theme or a top.phtml that is based on it. :x:x:x:

 

The correct way to do this is to open the theme/layout/customer.xml file and then modify the section that shows customer links on all pages, to include a link home and also a link to other customer service pages that you have deemed necessary, e.g. ‘returns’ (if you get a lot of those enquiries...).

By way of example, this modified XML file includes a ‘Home’ link and ‘Deliveries’, ‘Returns’ and ‘Contact Us’:

<!--
Default layout, loads most of the pages
-->

    <default>

        <!-- Mage_Customer -->
        <reference name="top.links">
            <action method="addLink" translate="label title" module="customer"><label>Home</label><url></url><title>Home</title><prepare>true</prepare><urlParams/><position>5</position></action>
            <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>94</position></action>
            <action method="addLink" translate="label title" module="customer"><label>Deliveries</label><url>deliveries</url><title>Deliveries</title><prepare>true</prepare><urlParams/><position>95</position></action>
            <action method="addLink" translate="label title" module="customer"><label>Returns</label><url>returns</url><title>Returns</title><prepare>true</prepare><urlParams/><position>96</position></action>
            <action method="addLink" translate="label title" module="customer"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare><urlParams/><position>97</position></action>
        </reference>
    </default>

 

This will allow you to add a Home link in the Top Links (My Account | My Wishlist | Etc.) before the My Account.

Find the file called links.phtml in app/design/frontend/default/default/template/page/template/ and make the following change:

<?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
    <div>
        <ul<?php if($this->getName()): ?>):?> id="<?php echo $this->getName() ?>"<?php endif;?>>
        
        <!-- HOME BUTTON HACK -->
        <li class="first"><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home') ?></a></li>
        <!-- HOME BUTTON HACK -->
        
            <?php foreach($_links as $_link): ?>
                <li <?php if($_link->getIsLast()): ?> class="last"<?php endif; ?><?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
            <?php endforeach; ?>
        </ul>
   </div>
<?php endif; ?>

 

NOTE: The if statement in the foreach loop has changed since “Home” will always be first, it wasn’t needed. Also note that the <li> for the “Home” link automatically gets the class “first”.

This allows for space between Home | My Account

分享到:
评论

相关推荐

    MicrosoftHTMLHelpWorkshopV1.3汉化版.rar

    与上面操作相同,不同的是在进行到“窗口属性”定义操作时,在[General]中指定 chm 文件标题栏中的文字“test2---带功能按钮的 chm 文件”,在[Button]中指定欲在 chm 文件的按钮区中显示的按钮如图(6)。...

    Visual C++编程技巧精选集 光盘

    242.如何在程序视图窗口中添加插入符 243.如何实现QQ抽屉导航效果的界面 244.如何使用树形视图导航程序界面 第7章 程序管理和控制 245.如何捕获按下的Home等功能键 246.如何捕获按下的Air或Shift+Alt组合键 247....

    e2e-warmup:用于端到端测试的gSchool预热

    通过导航栏中的链接转到“创建星球”页面页面网址应包含“ / editor” 它应该能够创造一个星球 点击“水彩”按钮 通过单击两次“添加树”按钮来添加两棵树 在“行星名称”输入中输入行星名称 在“行星描述”输入中...

    decorations:向Legal Server添加装饰的示例

    :这会将闪烁的圣诞灯添加到Legal Server页面的蓝色导航栏中。 :这会在Legal Server页面上添加其他各种节日装饰,例如将面包屑导航中的“首页”替换为侧边栏中的“ Ho,ho,home!”,“包装纸”,和背景中的一棵...

    Microsoft SQL Server 2005 Express Edition SP3

    在任务栏中,依次单击“开始”和“运行”,在“运行”文本框中键入 regedit.exe,再单击“确定”。 导航到以下注册表项:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib]。查找下列项...

    JAVA上百实例源码以及开源项目

     util实现Java图片水印添加功能,有添加图片水印和文字水印,可以设置水印位置,透明度、设置对线段锯齿状边缘处理、水印图片的路径,水印一般格式是gif,png,这种图片可以设置透明度、水印旋转等,可以参考代码...

    Foundation 侧边栏

    Foundation 侧边栏 侧边栏导航 Foundation 使用 创建侧边栏: 实例   Link 1   ...激活链接与分割线 ...我们可以使用网格设计模式来设置侧边导航栏,实例如下: 实例       Home   Learn HTML  ...   

    WordPress主题 大前端 阿里百秀 XIU ALIBAIXIU 小清新CMS高级主题[更新v3.2]

    增加:导航在顶部的2栏布局(后台主题设置中); 增加:2种分页模式的选择(后台主题设置中); 增加:指定一个或多个分类下文章不显示在首页(后台主题设置中); 增加:文章页面上一篇和下一篇模块; 增加:文章...

    Wordpress 博客主题/模板 阿里百秀XIU主题 2.1最新版CMS高级主题

    增加:导航在顶部的2栏布局(后台主题设置中); 增加:2种分页模式的选择(后台主题设置中); 增加:指定一个或多个分类下文章不显示在首页(后台主题设置中); 增加:文章页面上一篇和下一篇模块; 增加:文章...

    node-openshift:尝试在openshift上使用mongodb运行容器化节点

    节点开放移位 如何使用这个专案: 如果您还没有,请提供一个OpenShift容器平台环境。 导航到OpenShift Web控制台。 在OpenShift中创建一个新项目。... 在搜索栏中输入MongoDB,然后在“数据存储”下选择适当

    readium.github.io:用于存放组织网页的登录页面的基本回购

    该导航栏与readium.org导航栏并不完全相同,因为它仅提供指向目录的链接和简化的“关于”菜单(该菜单会发回到readium.org网站)。 Readium徽标还发回到readium.org主页,即面包屑中Home条目的同上。 根目录仅包含...

    Portfolio-App

    现在,我们的目标是在您的网站中添加新页面。 项目需求 您的应用程序应具有“主页”,“项目”,“博客”和“关于页面”。 标头 创建具有3个链接的导航栏 在右侧,应该有一个带有您的名字或图像的主页按钮。 在...

    PHP基础教程 是一个比较有价值的PHP新手教程!

    在那里还有一些其他教程的链接。而本文的该部分将让你对PHP熟悉一点。我不可能做到没有任何遗漏,我的目的只在于能让你迅速开始你的PHP编程。 2.1 首要条件 你首先必须要有一个正在工作着的支持PHP的web服务器。我...

    新版Android开发教程.rar

    � GPS 卫星导航功能,手机照相, MP3 ,蓝芽等均被列为 Android 所提供支持的基本选项。 � Android 的平台基本上是免费的,虽然有部份原生链接库会要求费用,但大部份是免权利金; Android 的 程序可以采用 JAVA ...

    网管教程 从入门到精通软件篇.txt

     bootcfg /add 向引导列表中添加 Windows 安装。  bootcfg /rebuild 重复全部 Windows 安装过程并允许用户选择要添加的内容。  注意:使用 bootcfg /rebuild 之前,应先通过 bootcfg /copy 命令备份 boot.ini...

    Google Android SDK开发范例大全(第3版) 1/5

    6.25 在SDK开发环境中访问JNI接口 第7章 娱乐多媒体 7.1 访问Drawable资源的宽和高 7.2 绘制几何图形 7.3 手机屏幕保护程序 7.4 用手指移动画面里的照片 7.5 加载存储卡的Gallery相簿 7.6 取得手机内置媒体中的图片...

    Google Android SDK开发范例大全(第3版) 4/5

    6.25 在SDK开发环境中访问JNI接口 第7章 娱乐多媒体 7.1 访问Drawable资源的宽和高 7.2 绘制几何图形 7.3 手机屏幕保护程序 7.4 用手指移动画面里的照片 7.5 加载存储卡的Gallery相簿 7.6 取得手机内置媒体中的图片...

Global site tag (gtag.js) - Google Analytics