【问题标题】:Can't retrieve the magento sub category images无法检索 magento 子类别图像
【发布时间】:2012-08-14 09:46:02
【问题描述】:

我正在尝试在父类别的页面上显示子类别网格。 我已经按照this 教程进行操作,一切正常,除了即使我为每个子类别分配了图像,页面仍然显示占位符图像而不是实际图像。

我认为 phtml 代码的某个地方有问题。

// Retrieve the current category and it's children
<?php
$_maincategorylisting=$this->getCurrentCategory();
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
    foreach ($_categories as $_category):
        if($_category->getIsActive()):
            $cur_category=Mage::getModel('catalog/category')->load($_category->getId());
            $layer = Mage::getSingleton('catalog/layer');
            $layer->setCurrentCategory($cur_category);
            $catName = $this->getCurrentCategory()->getName();
            $_imageUrl=$cur_category->getImageUrl();
            if (!$_imageUrl) : //if the image url is false set it to the placeholder 
                $_imageUrl = $this->getSkinUrl('images/catalog/product/placeholder/thumbnail.jpg');
            endif;
            /* output */ ?>
                <div class="category-box">
                    <a href="<?php echo $this->getCategoryUrl($_category)?>">
                        <img src="<?php echo $_imageUrl?>" height="80">
                    </a>
                    <p><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></p>
                </div>
        <?php endif;
    endforeach;
    $layer->setCurrentCategory($_maincategorylisting);
endif; ?>

注意事项:

我正在运行 Magento v 1.6.0.0

This 是我正在测试的类别页面。

【问题讨论】:

    标签: php magento magento-1.6 mage


    【解决方案1】:

    我注意到,在 foreach 循环中,您使用 $this->getCurrentCategory() 总是会返回“Filtrare”类别。

    基本上在 foreach 循环中你需要在任何地方替换 $this->getCurrentCategory() 和 $cur_category

    【讨论】:

    • 我听从了你的建议,但子类别图像没有任何变化
    • @Bogdan 我和我的队友尝试了教程中的代码,您提到并为我们工作。我们注意到一些不好的 php 风格,比如使用 而不是 。您能告诉我们,您的 Magento 安装中有多少商店浏览量?
    • 此外,这里的代码格式正确,某些版本的 php 不会抛出错误,因为这种脚本样式 " ?>" gist.github.com/3359512
    • 我只有一个商店视图,关于不良格式的好点,我将 &lt;? 替换为 &lt;?php
    • 你能检查一下图片的网址是什么...检查一下以供参考:awesomescreenshot.com/0afd8bka2
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2011-07-22
    相关资源
    最近更新 更多