我想通過爲我的單獨類別提供一些帶有子級鏈接的選項卡來讓我的大型目錄具有一定的平板友好性。因此,如果用戶點擊(第一級)頭部類別,則需要顯示包含每個直接孩子的圖片,描述和網址的所有塊以及所示的所有基礎(第三級)兒童類別的列表(第二級別)分類。請問你們有沒有這麼熱心檢查我的代碼?如何在Magento中顯示當前類別的兒童子類別
<?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 $children = explode(",", $this->getCurrentCategory()->getChildren()); ?>
<ul class="category-grid">
<div class="category-list">
<?php foreach($children as $child): ?>
<?php $_child = Mage::getModel('catalog/category')->load($child); ?>
<li class="item">
<a href="<?php echo $_child->getURL() ?>" target="_self"><img title="<?php echo $this->htmlEscape($_child->getName()) ?>" src="<?php echo $this->htmlEscape($_child->getImageUrl()) ?>" alt="<?php echo $this->htmlEscape($_child->getName()) ?>" /></a>
<div class="subcategory-title">
<a href="<?php echo $_child->getURL() ?>" title="<?php echo $this->htmlEscape($_child->getName()) ?>"><?php echo $this->htmlEscape($_child->getName()) ?></a>
</div>
<div class="description-block"> <?php echo $_child->getDescription(); ?></div>
<div class="children-links"><?php
$_helper = Mage::helper("catalog/category");
$rootCat = Mage::app()->getStore()->getRootCategoryId();
$current = Mage::registry('current_category');
if ($child){
//look for anchestor
$parentid = $child->getParentId();
$parent = Mage::getModel("catalog/category")->load($parentid);
if($parentid != $rootCat)
{
//find the anchestor
show_cat($parent,$_helper,$rootCat);
}else{
//is root
$_subcategories = $child->getChildrenCategories();
echo $_child->getAll_Children();
if(count($_subcategories)>0){
echo '<ul>';
foreach($_subcategories as $_category){
echo '<li>';
echo '<a href="'.$_helper->getCategoryUrl($_category).'">'.$_category->getName().'</a>';
if($child->getId() == $_category->getId()){
$current = Mage::registry('current_category');
if ($current){
//handle current
$_current_subcategories = $current->getChildrenCategories();
if(count($_current_subcategories)>0){
//the current cat has childrens
echo '<ul>';
foreach($_current_subcategories as $_sub_category){
echo '<li>';
echo '<a href="'.$_helper->getCategoryUrl($_sub_category).'">'.$_sub_category->getName().'</a>';
echo '</li>';
}
echo '</ul>';
}else{
//the current cat has no childrens
$current_parent = $current->getParentId();
$current_parent = Mage::getModel("catalog/category")->load($current_parent);
$_current_subcategories = $current_parent ->getChildrenCategories();
echo '<ul>';
foreach($_current_subcategories as $_sub_category){
echo '<li>';
echo '<a href="'.$_helper->getCategoryUrl($_sub_category).'">'.$_sub_category->getName().'</a>';
echo '</li>';
}
echo '</ul>';
}
}
}
echo '</li>';
}
echo '</ul>';
}
}
}
?>
</div>
</li>
<?php endforeach ?>
</div>
</ul>
好的,而不是上面的代碼,我剛剛添加:htmlEscape($_child->getChildren()) ?>這將獲得所有子類別children_id。任何關於如何讓他們顯示正確的名稱/網址? –