我正在一个名为 home_banner.phtml 的 phtml 文件中为我的 magento 网站制作一个自定义主页,我又通过以下代码在 CMS->Pages->Home Page 内容中引用了该主页

{{block type="core/template" template="theme/home_banner.phtml"}}

在我的 home_banner.phtml 中,我调用了tags/popular.phtml 来显示流行标签。

<div class="last-posts-grid clearfix">

     <?php echo $this->getLayout()->createBlock('core/template')->setTemplate('tag/popular.phtml')->toHtml(); ?>

</div>

然而,即使正确调用了“查看所有标签”id 的锚标签,标签也不会显示。ul class="tags-list" 在页面源中也可见,但标签本身不可见。有什么建议么?

有帮助吗?

解决方案

你需要改变块类型 core/templatetag/popular

<?php echo $this->getLayout()->createBlock('tag/popular')->setTemplate('tag/popular.phtml')->toHtml(); ?>

或者

给出块的名称

{{block type="core/template" template="theme/home_banner.phtml"  name="myname"}}

然后

通过使用 xml 参考 include Tags/popular.phtml

在 app/design/frontend/youupackage/yourtemplate/layout 创建 local.xml

把这个代码

<?xml version="1.0"?>
<layout version="0.1.0">
    <cms_index_index translate="label">
      <reference name="myname">
            <block type="tag/popular" name="home_tags_popular" template="tag/popular.phtml"/>
        </reference>
    </cms_index_index>
</layout>

并将以下代码放在 home_banner.phtml

echo $this->getChildHtml('home_tags_popular');
许可以下: CC-BY-SA归因
scroll top