我用這個$categories
在頁面中獲取分類圖像
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('level',2)
->addIsActiveFilter()
->addAttributeToSort('position');
foreach($categories as $cat) {$children=$cat->getChildrenCategories();}
選項1
//option 1
$children = $category->getChildren();
foreach(explode(',', $children) as $child):
$sub = Mage::getModel('catalog/category')->load($child);
$sub->getName() // this return ok, name show up
$sub->getImageUrl() // this return ok, image show up
選項2級的作品,但無法獲取圖像的URL一些原因。
//option 2
$children = $category->getChildrenCategories();
foreach($children as $sub):
$sub->getName() // this return ok, name show up
$sub->getImageUrl() // this return empty, image NOT show up so is other attribute beside name.
有人可以解釋區別嗎?我怎麼會去選擇2
它只有在清除加載的集合,添加屬性以再次選擇並加載集合時纔有效:$ category-> getChildrenCategories() - > clear() - > addAttributeToSelect('image_url') - >加載();無論如何,這是比我的更好的方法;] – SeStro 2015-02-25 13:37:01
非常感謝你,我真的很沮喪,如果我添加另一個 - >加載它增加我的加載時間整整2秒(沒有緩存)。 – aahhaa 2015-02-25 14:46:20
等。 igive你解決方案 – 2015-02-25 14:47:24