1

そのため、個々のサブカテゴリの画像を取得するいくつかのコードが浮かんでいます。

foreach ($collection as $cat){
    $cur_category = Mage::getModel('catalog/category')->load($cat->getId());
    $layer = Mage::getSingleton('catalog/layer');   
    $layer->setCurrentCategory($cur_category);
    $_img = $this->getCurrentCategory()->getImageUrl();
}

$cat画像を取得しようとしているサブカテゴリはどこですか。私が直面している問題 - サブカテゴリの画像はすべて同じです! サブカテゴリの最初の画像は、ページに表示される画像です。ただし、リンクと名前はすべて正しいです:(これもforループ内にあります)

<div>
    <a href="<?php echo $helper->getCategoryUrl($cat);?>">
        <img src="<?php echo $_img; ?>" title="<?php $cat->getName() ?>"/>
        <cite><?php echo $cat->getName();?></cite>
    </a>
</div>

でこの変更を行っていcatalog/category/view.phtmlます。示されているよりも少し多くありますが、これがすべての関連情報です。

編集

すべてのカテゴリには独自の画像があり、適切にアップロードされています。それらは管理者に正しく表示されます。また、$cat->getId()個々のサブカテゴリの正しい ID を返しています。

4

3 に答える 3

2

画像の URL を取得するときに間違っている可能性があります。

使用する代わりに

$_img = $this->getCurrentCategory()->getImageUrl(); 

以下のコードを試してください

$_img = $cur_category->getImageUrl();
于 2012-11-27T05:55:47.770 に答える
2

@RandyHall, are your sure that $this->getCurrentCategory() will get the category from the same place as $layer->setCurrentCategory($cur_category); will set it to?

Watch the source code here and here. As you can see category is set to the layer model and get returns category from registry(via call to block).

So I would suggest you to do something like this:

$_img = $layer->getCurrentCategory()->getImageUrl();
于 2012-11-27T15:13:01.020 に答える
2
foreach ($collection as $cat){
    $cur_category = Mage::getModel('catalog/category')->load($cat->getId());
    $_img = $cur_category->getImageUrl();
}

これがあなたの目的のように見えますか?

于 2012-11-27T15:47:53.493 に答える