[英]how to get thumbnail images on list.phtml page in magento 1.9.2.4
[英]Magento - list categories, subcategories, and images in phtml file
我正在嘗試在每個Magento頁面的頁眉中創建一個下拉菜單。 我想列出所有類別,子類別以及與之相關的圖像。 通過從Internet抓取和合並代碼,我提出了一個幾乎可行的解決方案,只有子類別的URL返回的是未定義的,而且我不知道為什么。 有任何想法嗎? 這是我的代碼:
<?php
$cats = Mage::getModel('catalog/category') -> load(2) -> getChildren();
$catIds = explode(',', $cats);
$categories = array();
foreach ($catIds as $catId) {
$category = Mage::getModel('catalog/category') -> load($catId);
$categories[$category -> getName()] = array('name' => $category -> getName(), 'url' => $category -> getUrl(), 'img' => $category -> getImageUrl(), 'subcategories' => Mage::getModel('catalog/category') -> getCategories($catId));
}
ksort($categories, SORT_STRING);
?>
<ul>
<?php foreach($categories as $name => $data): ?>
<li><?php echo $data['name']; ?>
<a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>">
<img class="cat-image" src="<?php echo $data['img']; ?>" />
</a>
<ul>
<?php
foreach ($data['subcategories'] as $subcategory) {
echo "<a href='" . $subcategory -> getUrl() . "'><li>" . $subcategory -> getName() . "</li></a>";
}
?>
</ul>
</li>
<?php endforeach; ?>
</ul>
嘗試改變
'subcategories' => Mage::getModel('catalog/category') -> getCategories($catId)
至
'subcategories' => $category->getChildrenCategories()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.