
在用户未登录的时候,magento的欢迎语是很简单的,今天我们来让我们的欢迎语更酷点。如上图。
首先我们来看下默认的magento登录与欢迎语,如下图

进行下面操作前请先关闭magento的缓存,本例使用magento1.5版本的default模板,请将模板路径换到你所用的模板路径,其它版本可能略有不同。
1.我们为了达到目的,就先将这个login删了,打开你的模板文件包,如果是default模板,路径如下:app\design\frontend\base\default\layout\customer.xml (注意:你要打开你的模板文件夹中的layout\customer.xml)。
删除或者注释掉如下的代码
<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> </reference>
那么上图的login就删掉了。
2.下面我们来看下,如何改掉这个Default welcome msg!,我们从代码中将它删掉先,写个新的。
打开app\design\frontend\base\default\template\page\html\header.phtml (注意打开你的模板的这个文件)
找到如下代码
<p class="welcome-msg"><?php echo $this->getWelcome()?></p>
替换成
<?php echo $this->getChildHtml('cool_welcome') ?>
$this->getwelcome()这个删了,后台的system->configuration->design->header中的Welcome Text设置便不管用了,所以你要是根据本教程修改,这个功能就给删了,当然,还有其它的办法让这个继续起作用,但是由于还要稍微复杂点,本讲就不讲了。
3.先在我们就在代码中删掉了原先的Default welcome msg!这句话,我们来写个我们自己的cool welcome
在app\design\frontend\base\default\template\page\html中新建文件 cool_welcome_login.phtml和cool_welcome_logout.phtml文件(注意我使用的是default模板,在你的模板中新建)
在cool_welcome_login.phtml中加入如下代码
<p class="welcome-msg"> <?php echo $this->__('Welcome!') ?>, <a style="display:inline" href="<?php echo $this->getUrl('')?>customer/account/login"><?php echo $this->__('Login') ?></a> <?php echo $this->__('or') ?> <a style="display:inline" href="<?php echo $this->getUrl('')?>customer/account/create"><?php echo $this->__('Register here') ?></a> </p>
在cool_welcome_logout.phtml中加入如下代码
<p class="welcome-msg"> <?php echo $this->__('welcome') ?> <?php echo Mage::getSingleton('customer/session')->getCustomer()->getName() ?>! </p>
4.我们回到我们步骤1中的文件customer.xml中,找到<customer_logged_in>与<customer_logged_out>两段代码,更新到如下内容
<customer_logged_in> <reference name="top.links"> <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> <reference name="header"> <block type="core/template" name="welcome_logout" as="cool_welcome" template="page/html/cool_welcome_logout.phtml"/> </reference> </customer_logged_in> <!-- Load this update on every page when customer is logged out --> <customer_logged_out> <reference name="header"> <block type="core/template" name="welcome_logout" as="cool_welcome" template="page/html/cool_welcome_login.phtml"/> </reference> <remove name="wishlist_sidebar"></remove> <remove name="reorder"></remove> </customer_logged_out>
5.大功告成了,登录看下效果吧
转载表明出处:www.hellokeykey.com
确实很酷,学会了,灰常感谢钥匙!!!
呵呵,加油!
学习了,感谢。
你好KEY:
我自己改了下,
未登录:您好,欢迎来到商店![Login] [Register]
登录后:Welcome, zhang ding![Logout]
欢迎语我还是调用的后台设置的,我想请问一下,这登录后的这个Welcome,是在那个文件里找了半天没有找到。这里我用了个if来判断是否已登录。功能是实现了,就是这个登录后的欢迎语Welcome不知道该在那里改动。
你好,Magento欢迎语后台修改位置在 System ->Configurable ->Design -> Header位置,我在视频中也有提及,请将我的使用视频看一遍吧。
登录前的我知道,登录前已经是我设置的了,就是登录后的是一个Welcome。
登录前:您好,欢迎来到商店![Login] [Register]
登录后:Welcome, xxx![Logout]
登录前的确已经是显示的是后台Welcome Text里面的内容了。我就是问登录后它那个Welcome, xxx!是在那个文件里面。我把例子放到www.onssc.com上面,你看看就知道是怎么回事了。
Hello,Key!
我想在新建的cool_welcome_login.phtml繼續使用__(‘Welcome!’) ?>我該怎麼做呢。我直接加入不顯示!
xml文件你要更新,并且你要更新你正在使用的模板的xml文件,如教程中说的