Magento - 如何替换“Home”在面包屑中?

发布于 2024-10-04 12:36:18 字数 1245 浏览 6 评论 0原文

我只是想知道是否有人有在 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>&gt;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

停滞 2024-10-11 12:36:18

事实上,您可以隐藏第一个“Home”,使其不出现在面包屑中,而不会弄乱 CSS 并保持 HTML 干净。

只需将规则“!$_crumbInfo['first']”添加到您的 if 条件中,就像:

<?php if ($crumbs && is_array($crumbs)): ?>
    <?php foreach ($crumbs as $_crumbName => $_crumbInfo): ?>
        <?php if ($_crumbInfo['link'] && !$_crumbInfo['first']): ?>
            <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
        <?php elseif ($_crumbInfo['last']): ?>
            <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
        <?php elseif (!$_crumbInfo['first']): ?>
            <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
        <?php else: ?>
        <?php endif; ?>
        <?php if (!$_crumbInfo['last'] && !$_crumbInfo['first']): ?>
            » 
        <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>

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:

<?php if ($crumbs && is_array($crumbs)): ?>
    <?php foreach ($crumbs as $_crumbName => $_crumbInfo): ?>
        <?php if ($_crumbInfo['link'] && !$_crumbInfo['first']): ?>
            <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
        <?php elseif ($_crumbInfo['last']): ?>
            <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
        <?php elseif (!$_crumbInfo['first']): ?>
            <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
        <?php else: ?>
        <?php endif; ?>
        <?php if (!$_crumbInfo['last'] && !$_crumbInfo['first']): ?>
            » 
        <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>
画尸师 2024-10-11 12:36:18

我认为这是在 app/code/core/Mage/Cms/Block/Page.php 中设置的。查看 _prepareLayout() 方法(我使用的是 magento 1.3,所以这可能有点过时)。

我看到您有几个更新选项。

  1. 直接编辑文件。 (不是我的建议,而是快速的方式)
  2. 覆盖您自己的模块中的类
  3. 创建主题的translate.csv 文件的条目。这是我在正常情况下喜欢更新措辞的方式,但这可能不适合你。因此,在 app/design/frontend/your_package/your_theme/locale/en_US/translate.csv 中,您可以添加一个新行,其中显示“Home”、“”,然后快速。
  4. 编辑 css 文件而不是 php/phtml 文件。如果您对 css 有一定的经验,您可能只需将文本缩进设置为 -2000em 并设置背景图像即可。

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.

  1. Edit the file directly. (not my recommendation, but the fasted way)
  2. Override the class in your own module
  3. Create an entry your theme's translate.csv file. This is the way I like to update verbiage under normal situations, but it may not be your cup of tea. So in app/design/frontend/your_package/your_theme/locale/en_US/translate.csv you can put a new line that says "Home","" and then presto.
  4. Edit your css file instead of php/phtml files. If you are halfway experienced with css you can likely just set the text-indent to -2000em and set a background image.
与君绝 2024-10-11 12:36:18

使用 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.

人疚 2024-10-11 12:36:18

无需为此编写任何代码,只需使用您的翻译文件,我们就可以更改面包屑中的“Home”。

为了这 :

转到您的主题 ->创建语言环境目录->创建en_us目录->创建翻译.csv。

在此只需写下代码

“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 :

goto your theme -> create locale directory-> create en_us directory -> create translate.csv .

In this just write below code

"Home","your choice".

柏拉图鍀咏恒 2024-10-11 12:36:18

编辑主题的 breadcrumbs.phtml 文件:

/app/design/frontend/[YOUR_THEME]/default/template/page/html/breadcrumbs.phtml

如果您想用图像替换主页面包屑:

<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
    <li class="<?php echo $_crumbName ?>">
    <?php if($_crumbInfo['first']): ?>
        <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>">
            <img src="/your/image/path.png"/>
        </a>
    <?php elseif($_crumbInfo['link']): ?>
        <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>

如果您想完全删除主页面包屑,这就是我需要的:

<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
    <?php if ($_crumbInfo['first']) continue ?>
    <li class="<?php echo $_crumbName ?>">
    <?php if($_crumbInfo['link']): ?>

Edit your theme's breadcrumbs.phtml file:

/app/design/frontend/[YOUR_THEME]/default/template/page/html/breadcrumbs.phtml

If you want to replace the Home crumb with an image:

<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
    <li class="<?php echo $_crumbName ?>">
    <?php if($_crumbInfo['first']): ?>
        <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>">
            <img src="/your/image/path.png"/>
        </a>
    <?php elseif($_crumbInfo['link']): ?>
        <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>

If you want to remove the Home crumb entirely, which is what I needed:

<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
    <?php if ($_crumbInfo['first']) continue ?>
    <li class="<?php echo $_crumbName ?>">
    <?php if($_crumbInfo['link']): ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文