0

我正在创建一个静态块来显示 Magento 中某个类别的子类别。代码由我编写,并在网络上获取了一些想法。这个想法是显示一个名为 back.png 的纯背景标题作为子类别的缩略图,当这个标题没有缩略图时,或者如果图像已上传,则显示类别缩略图。目前我无法显示缩略图,有人可以帮助我吗?谢谢。

<div class="product_list" style="width:900px;">
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if($currentCategory->children_count > 0) { ?>
<?php
    $cat = Mage::getModel('catalog/category')->load($currentCategory->entity_id);
    $_categories = $cat->getChildrenCategories();
?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category):  //print_r($_category); ?>
<?php
    $imageUrl = Mage::getModel('catalog/category')->load($_category->getId())->getThumbnailUrl();

    $imageName = substr(strrchr($imageUrl,"/"),1);
    $imagePrefx = Mage::getBaseUrl('media')."catalog/category/";
    $newImageUrl2 = $imagePrefx.$imageName;
?><div clas="subcat-el">

<li style="float:left; margin-right:10px;">
<div class="subcat-name" style="z-index:20; width:270px; position:absolute; margin-top:134px;text-align: center;">
    <a href="<?php echo $_helper->getCategoryUrl($_category) ?>" style="text-decoration:none;">
    <h3 style="margin-left:18px; font-family:Helvetica; font-weight:200;text-shadow: 1px 1px 1px #030;font-size: 24px;color:#fff; ">

            <?php echo $_category->getName()            ?>
    </h3>       
        </a> 

    </div>
    <div style="width:270px; height:270px;background: #fff;
                border: 9px solid #fff; border-radius: 3px;-webkit-border-radius: 3px;-moz-border-radius: 3px;-webkit-box-shadow: 0 0 6px 0 rgba(0,0,0,0.15);-moz-box-shadow: 0 0 6px 0 rgba(0,0,0,0.15);box-shadow: 0 0 6px 0 rgba(0,0,0,0.15);margin-bottom:10px;">
    <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
        <img src="<?php 
        if ($newImageUrl2 == $imagePrefx): $newImageUrl2 = Mage::getBaseUrl('skin')."/subcat/back.png";
        endif;
        echo $newImageUrl2; ?>" alt="<?php echo $_category->getName() ?>" style="width:100%;">
    </a>

    </div>  
</li>
</div>
<?php endforeach; ?>
</ul>
<br style="clear:left;" />
<?php endif; ?> 
<?php } else { echo "<h3>No Sub-category found</h3>"; } ?>
</div>
4

1 回答 1

0

默认情况下,您的行中没有这样的方法:

Mage::getModel('catalog/category')->load($_category->getId())->getThumbnailUrl();

你应该getThumbnail()试试

或者你可以像这样尝试

$imageUrl = Mage::getBaseUrl('media') . 'catalog/category/' . $_category->getThumbnail()

或者您可以尝试在自己的扩展中指定自己的方法 getThumbnailUrl

public function getThumbnailUrl(Mage_Catalog_Model_Category $category)
{
    return (bool)$category->getThumbnail()
        ? Mage::getBaseUrl('media') . 'catalog/category/' . $category->getThumbnail()
        : '';
}
于 2013-10-30T16:50:37.507 回答