Php 马根托';特色类别';未在前端加载图像

Php 马根托';特色类别';未在前端加载图像,php,magento,magento-1.9,Php,Magento,Magento 1.9,在我的Magento(1.9.3.3)管理面板中,我上传了每个类别的图像,我可以从类别编辑表单中看到它们。然而,在前端主页上,我的特色图片没有显示。如果我查看主页,每个类别图像src都是空白的: <img alt="" src=""> 生成此项的代码如下所示: <?php $_subcategories = Mage::getResourceModel('catalog/category_collection') ->addAttributeToSelect('*'

在我的Magento(1.9.3.3)管理面板中,我上传了每个类别的图像,我可以从类别编辑表单中看到它们。然而,在前端主页上,我的特色图片没有显示。如果我查看主页,每个类别图像src都是空白的:

<img alt="" src="">

生成此项的代码如下所示:

<?php
$_subcategories = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('is_featured', 1)
->addAttributeToSort( 'feature_position'); 

$_subcategories->getSelect()->limit(7,0);

$categories_count = count($_subcategories);
?>

<div class="row">
<?php 
$count = 0;
if($_subcategories): ?>
<ul id="myList">
    <?php foreach ($_subcategories as $cat): 
        $count = $count + 1; 
        if( $count > 6 ) {
            break;
        }
    ?>
        <li class="col-md-4 cat-item col-sm-4 col-xs-12" style="display: list-item;">
            <a class="image-link" href="<?php echo $cat->getUrl($cat);?>"><div class="feature-cat"><img alt="" src="<?php echo $cat->getImageUrl();?>">
                <div class="feature-cat-name"><?php echo $cat->getname(); ?></div>
            </div>
            </a>
        </li>
    <?php endforeach; ?>
    </ul>
<?php endif; ?>
</div>

因此,每个类别的最终HTML输出如下所示:

<a class="image-link" href="http://127.0.0.1/product-category/product1">
    <div class="feature-cat"><img alt="" src="">
        <div class="feature-cat-name">Batteries</div>
    </div>
</a>


知道什么$cat->getImageUrl()返回空值,但所有其他类别属性都可以吗?我做了很多事情都没有成功。谢谢大家!

还要将下面的属性添加到过滤器中,然后重试

$_subcategories = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('is_featured', 1)
->addAttributeToSort( 'feature_position')
->addAttributeToSelect('image');
然后获取for循环中每个类别的图像

foreach($_subcategories as $subcat) {
echo "Image : ".$subcat->getImage();
}
试试这个

  if($_category->getImageUrl()){
$catimg = $_category->getImageUrl(); 
}else{
$catimg=null;
continue;
或者只是

$catimg = $_category->getImageUrl();
这起到了作用:

$_subcategories = 
    Mage::getResourceModel('catalog/category_collection')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('is_active', 1)
    ->addAttributeToFilter('is_featured', 1)
    ->addAttributeToSort( 'feature_position')
    ->addAttributeToFilter('image', array('notnull' => true));