Magento - 如何替换“Home”在面包屑中?
我只是想知道是否有人有在 Magento 中格式化面包屑的经验?
我想用图像替换当前显示文本“HOME”的链接。
我认为这将是一个用图片替换某些文本的简单情况,但似乎“HOME”文本/链接是动态创建的,因为这就是 breadcrumbs.phtml 中的全部内容:
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
I'm just wondering if anyone has had any experience in formatting the breadcrumb in Magento?
I would like to replace the link that currently displays the text 'HOME' with an image.
I thought it would be a simple case of replacing some text with a picture but it seems the 'HOME' text/link is dynamically created as this is all that is in the breadcrumbs.phtml:
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
事实上,您可以隐藏第一个“Home”,使其不出现在面包屑中,而不会弄乱 CSS 并保持 HTML 干净。
只需将规则“!$_crumbInfo['first']”添加到您的 if 条件中,就像:
You can, in fact, hide that first "Home" from appear in your breadcrumbs without messing with CSS and keeping your HTML clean.
Just add the rule "!$_crumbInfo['first']" to your if conditions, just like:
我认为这是在 app/code/core/Mage/Cms/Block/Page.php 中设置的。查看 _prepareLayout() 方法(我使用的是 magento 1.3,所以这可能有点过时)。
我看到您有几个更新选项。
I think this is set in app/code/core/Mage/Cms/Block/Page.php. Look in the _prepareLayout() method (I am using magento 1.3, so this might be a little out of date).
I see you have a few options to update.
使用 CSS,这是一场并不值得的斗争:) 5 行 CSS 比尝试破解面包屑渲染器更容易解决这个问题。
Use CSS, this is a fight that isn't really worth it :) The 5 lines of CSS will take care of the issue much more easily than attempting to hack apart the breadcrumb renderers.
无需为此编写任何代码,只需使用您的翻译文件,我们就可以更改面包屑中的“Home”。
为了这 :
在此只需写下代码
“Home”、“your choice”。
No need to write any code for this,just using your translate file we can change "Home" in the breadcrumb.
For this :
In this just write below code
"Home","your choice".
编辑主题的 breadcrumbs.phtml 文件:
如果您想用图像替换主页面包屑:
如果您想完全删除主页面包屑,这就是我需要的:
Edit your theme's breadcrumbs.phtml file:
If you want to replace the Home crumb with an image:
If you want to remove the Home crumb entirely, which is what I needed: