2015-03-13 25 views

回答

0

看看這可以幫助你,

假設你已經在當前類別中變量$ category。 這段代碼應該給你所有(活動)類別的兄弟姐妹。

$siblings = Mage::getModel('catalog/category')->getCollection()->setStoreId(Mage::app()->getStore()->getId()); 
$siblings->addAttributeToSelect('*') 
     ->addAttributeToFilter('parent_id', $category->getParentId()) //siblings have the same parent as the current category 
     ->addAttributeToFilter('is_active', 1)//get only active categories 
     ->addAttributeToFilter('entity_id', array('neq'=>$category->getId()))//exclude current category 
     ->addAttributeToSort('position');//sort by position 

現在你可以遍歷的兄弟姐妹和列出他們:

<?php foreach ($siblings as $sibling): ?> 
    <a href="<?php echo $sibling->getUrl();?>"><?php echo $sibling->getName();?></a><br /> 
<?php endforeach;?> 

參考文獻: https://magento.stackexchange.com/questions/1303/how-to-show-category-siblings

相關問題