在我的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-&gt; getImageUrl()返回NULL,但所有其他类别属性都没问题?我尝试了许多没有成功的事情。谢谢!
答案 0 :(得分:0)
还要将以下属性添加到过滤器,然后尝试。
$_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();
}
答案 1 :(得分:0)
试试这个
$catimg = $_category->getImageUrl();
或者只是
keys.forEach(key => {
console.log(obj[key]);
});
答案 2 :(得分:0)
这有效:
$_subcategories =
Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('is_featured', 1)
->addAttributeToSort( 'feature_position')
->addAttributeToFilter('image', array('notnull' => true));