【问题标题】:Magento skin url 'default' replaced with 'theme'?Magento皮肤网址“默认”替换为“主题”?
【发布时间】:2015-07-03 16:54:27
【问题描述】:

我在 magento 上使用自定义主题,在 header.phtml 中使用了以下代码:

<div class="logo">
    <a href="<?php echo $this->getUrl('') ?>">
        <img src="<?php echo $this->getSkinUrl('').'images/logo_white.gif'//$this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
    </a>
</div>   

当我第一次加载主页时,getSkinUrl 给了我这个路径:

http://site.address.com/skin/frontend/THEME/DEFAULT/images/logo_white.gif

但是,当我加载任何其他页面时,我得到:

http://site.address.com/skin/frontend/THEME/THEME/images/logo_white.gif

如果不是任何地方的主页,我无法找到为什么皮肤路径会改变。唯一不同的是,我们有这样一种效果,即在基础上添加一个徽标以改变颜色:

<?php if ($this->getIsHomePage()):?>
<div class="back-header">
    <div class="logo">
        <a href="<?php echo $this->getUrl('') ?>">
            <img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
        </a>
    </div>
</div>
<?php endif;?>

但这以前有效吗?

让我知道你们的想法。谢谢!

【问题讨论】:

    标签: php css magento url-rewriting theming


    【解决方案1】:

    在管理System(Menu) -&gt; Configuration -&gt; General(Sidebar) -&gt; Design -&gt; Header(Section) -&gt; Logo Image Src 中设置 URL。并确保您的主题定义了这个,否则 Magento 后备将发生在您的定义不存在的地方。然后将硬编码链接恢复为$this-&gt;getLogoSrc()

    【讨论】:

      【解决方案2】:

      我不知道这是否能回答您的问题,但它可能会解决您的问题。
      切勿将 getSkinUrl() 与空参数一起使用。
      所以不要这样:

      echo $this->getSkinUrl('').'images/logo_white.gif'
      

      使用

      echo $this->getSkinUrl('images/logo_white.gif');
      

      Magento 在当前主题中查找指定路径。如果找到它,它会将 url 返回到资源。如果没有,它会查看您设置为默认的主题,如果它不存在,它将从 base/default 返回该资源的 url,而忽略资源是否存在。

      [编辑]。 我可能也知道为什么您会为不同的页面获得不同的值。
      header.phtml 中应该有 2 段代码用于标识。一个用于主页,一个用于其余页面。也许你只修改了一个。

      <?php if ($this->getIsHomePage()):?> <-- for homepage-->
          <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:?><-- for the rest of the pages-->
          <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?>
      

      【讨论】:

      • 谢谢,但我之前使用了一个空的 getSkinUrl() 并且没有指定“else”,并且它已经工作了。很奇怪。
      • 也许你只是幸运。 :) 无论如何,您不应该使用带有空参数的方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      相关资源
      最近更新 更多