2012-03-07 7 views
0

私は、以下のコードで取得する現在の子カテゴリのリストにカテゴリ画像を取得したいと思います。カテゴリ画像を持つ現在の子カテゴリ

どうすればいいですか?

<?php 
$i=0; 
$count=1; 
echo '<div class="empty-row">'; 
$_categories = $this->getCurrentChildCategories(); 
foreach($_categories as $_category): 
{ 
if($i %3 ==0) 
    { ?> 
    </div> 
    <div class="row"> 
     <div class="item <?php if($count > 6) echo 'nobg'; ?>"> 
      <h2><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?> &raquo;</a></h2> 
     </div> 
    <? } 
    else 
    { ?> 
     <div class="item <?php if($count > 6) echo 'nobg'; ?>"> 
      <h2><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?> &raquo;</a></h2> 
     </div> 
    <? } 
    $i++; 
} 
$count++; endforeach; 
?> 

答えて

2

ここでは、画像とともに子カテゴリを取得しています。ルートカテゴリを取得したい場合は、コードを変更するだけです。

<?php 
    $layer = Mage::getSingleton('catalog/layer'); 
    $_category   = $layer->getCurrentCategory(); 
    $_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description')) 
     ->addAttributeToFilter('is_active', 1) 
     ->addIdFilter($_category->getChildren()) 
     ->setOrder('position', 'ASC') 
     ->joinUrlRewrite(); 
?> 
<?php foreach ($_categories as $_category): ?> 
    <?php if($_category->getIsActive()): ?> 
      <img src="<?php echo $this->htmlEscape($_category->getImageUrl()) ?>" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" /> 
      <a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a> 
    <?php endif; ?> 
<?php endforeach; ?> 
+0

ありがとうございました! – Michael

関連する問題