magento 根目录显示子目录

magento 根目录显示子目录

1.进入后台cms->Static Blocks 创建静态页,在今天页面内容输入

[sourcecode language=”plain”]{{block type="catalog/navigation" template="catalog/navigation/sub-categories.phtml"}}[/sourcecode]

2. 在Catalog->Manage Categories->选中目录->Dispaly Settings 中Display Mode 选择静态块或者静态块和产品块,CMS Block找到自己创建的静态块,后面保存

3.在app/code/local/Mage/Catalog/Model/Category.php中查找getImageUrl方法在

[sourcecode language=”plain”]
public function getImageUrl()
{
$url = false;
if ($image = $this->getImage()) {
$url = Mage::getBaseUrl(‘media’).’catalog/category/’.$image;
}
return $url;
}
[/sourcecode]

后面添加缩略图

[sourcecode language=”plain”]
public function getThumbnailImageUrl($fullpath = false){
$url = false;
if($image = $this->getThumbnail()){
if($fullpath == true){
$url = Mage::getBaseUrl(‘media’) . ‘catalog/category/’ . $image;
}else{
$url = $image;
}
}
return $url;
}
[/sourcecode]

4.在模板目录catalog/navigation中创建sub-categories.phtml里面写入
[sourcecode language=”plain”]
<div class="block-layered-nav-view">
<div class="block-layered-nav-content">
<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>

<?php if($_categories->count()):?>
<?php foreach ($_categories as $_category):?>
<?php if($_category->getIsActive()):
$cur_category=Mage::getModel(‘catalog/category’)->load($_category->getId());
$layer = Mage::getSingleton(‘catalog/layer’);
$layer->setCurrentCategory($cur_category);

$catName = $this->getCurrentCategory()->getName();
?>
<dl class="p_graw">
<dt><a href="<?php echo $this->getCategoryUrl($_category) ?>"><?php echo $catName ?></a></dt>
<dd>
<ol>
<li class="p_l_images">
<?php if($_imageUrl = !$this->getCurrentCategory()->getThumbnailImageUrl()): ?>
<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo $this->getSkinUrl(‘images/media/subcategory-default.jpg’) ?>"></a>
<?php endif; ?>
<?php if($_imageUrl = $this->getCurrentCategory()->getThumbnailImageUrl()):?>
<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo Mage::getBaseUrl(‘media’) . ‘catalog/category/’ . $_imageUrl; ?>" width="300" height="180" /></a>
<?php endif; ?>
</li>
<li class="p_right">
<p><?php echo $this->getCurrentCategory()->getDescription();?></p>
<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo $this->getSkinUrl(‘images/media/Bullet_MoreInfo.gif’)?>" /></a>
</li>
</ol>
</dd>
</dl>
<?php endif;?>
<?php endforeach; ?>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
<?php endif;?>
</div>
</div>
[/sourcecode]

发表评论

© 2022. powered by PHP 个人小站