【问题标题】:Magento 1.9 add a static block only shown on startpageMagento 1.9 添加了仅在起始页上显示的静态块
【发布时间】:2014-11-03 14:43:46
【问题描述】:

我想在页脚中添加一个静态块。

当我将此代码放入 header.phtml 时,它将在标题中工作:

<code>
<?php
$is_homepage = Mage::getBlockSingleton('page/html_header')->getIsHomePage();
if($is_homepage)
{
echo "Dies ist die Homepage!";
} else {
echo "Dies ist NICHT die Homepage!";
}
?>
</code>

但是当我想把这段代码放在 footer.phtml 中时,它就不起作用了。可能是什么问题?

我需要一种简单的方法来在起始页上显示我的 seo 文本。

【问题讨论】:

    标签: magento static magento-1.9.1


    【解决方案1】:

    对于页脚,您也可以使用此代码,但不要忘记从 Magento 管理员中删除缓存以查看更改。

    <?php
    $homepage = Mage::getBlockSingleton('page/html_header')->getIsHomePage();
    if($homepage)
    {
        echo "Homepage!";
    } else {
        echo "NOT on Homepage!";
    }
    ?>
    

    或者,如果您只想在主页页脚上显示特定的静态块,只需通过主页资源调用它。为此,导航到 CMS > Pages > 选择主页并单击左侧栏中的设计并将代码放在这里,即

    <reference name="footer"> 
        <block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"> 
            <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/> 
            <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/> 
            <block type="cms/block" name="custom_footer_block"> 
                <action method="setBlockId"> 
                    <block_id>custom_footer_block</block_id> 
                </action> 
            </block> 
        </block> 
    </reference>
    

    希望对你有帮助,

    谢谢

    【讨论】:

      【解决方案2】:

      如果你想检查,页面是主页,那么你可以使用这个条件

      <?php 
          if(Mage::getSingleton('cms/page')->getIdentifier() == 'home'  && 
             Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
          {
          //condition
          }
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-28
        • 2011-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-09
        相关资源
        最近更新 更多