我无法从数组创建 foreach 请求数据。
从 Magento 请求名称、URL 和图像的示例:
<?php
$cat_id = array(268, 269, 270, 271, 272, 273, 274, 275, 276);
$helper = Mage::helper('catalog/category');
?>
<div class="main">
<?php foreach ($cat_id as $id):?>
<div class="category">
<a href="<?php echo $helper->getCategoryUrl($id); ?>">
<img src="<?php echo $helper->getThumbnailUrl($id); ?>" title="<?php echo $helper->getName($id); ?>"/>
<div class="text"><h2><?php echo $helper->getName($id); ?></h2></div>
</a>
</div>
<?php endforeach; ?>
</div>
问题是我什么都想不出来,也没有给出错误,如果有人能告诉我出了什么问题,我真的很感激?
Vladimir Boliev 提供的解决方案:
<?php
$cat_id = array(268, 269, 270, 271, 272, 273, 274, 275, 276);
?>
<div class="main">
<?php foreach ($cat_id as $id):?>
<?php $cur_category = Mage::getModel('catalog/category')->load($id);
$url = $cur_category->getUrl();
$name = $cur_category->getName();
$img = $cur_category->getThumbnailUrl();
?>
<div class="category">
<a href="<?php echo $url; ?>">
<img src="<?php echo $img; ?>" title="<?php echo $name; ?>"/>
<div class="text"><h2><?php $name; ?></h2></div>
</a>
</div>
<?php endforeach; ?>
</div>