2012-03-07 57 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

這裏是GET子類別,有圖像,如果你想獲得根類爲好,只是修改代碼。

<?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 2012-03-07 08:35:40