I found the answer on another wiki- http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/navigation/how_to_create_a_vertical_left_hand_menu
I just change my .phtml file to one called home_nav.phtml and added this code.
<div class="vertical-nav-container box base-mini">
<div class="vertical-nav">
<!--<div class="head">-->
<!--<h4>-->
<div class="block block-cart">
<div class="block-title">
<strong><span><?php echo $this->__('Categories') ?></span></strong>
</div><!--End block block-cart-->
<div class="block-content">
<!--</h4>-->
<!--</div>--><!--End Of head-->
<h4 class="no-display">
<?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav_vert">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?> </ul>
</div>
</div><!--End Of vertical-nav-->
<?php echo $this->getChildHtml('topLeftLinks') ?>
</div></div><!--End Of vertical-nav-container box base-mini-->
Then displayed the code in a block using
{{block type="catalog/navigation" name="catalog.category" template="catalog/navigation/vert_nav.phtml"}}
a more detailed answer can be found on the wiki link at the top
Hopefully this can help soemone as i struggled with this for some time.
Good question!
The trick here is to extend a block based on catalog/product_list.
I think the best way here is to add some xml to the "Layout Update XML" section.
<reference name="content">
<block type="catalog/product_list"
name="multiple_categories" template="catalog/product/list.phtml">
<action method="setCategoryIds"><category_ids>4,5,6,7</category_id></action>
</block>
</reference>
Here you have to replace catalog/product_list with your created custom module block. SetCategoryIds sets the categoryids in this block so you can filter on them.
In product/list.phtml is this called to get the product collection:
$_productCollection=$this->getLoadedProductCollection();
The trick here is to create a custom module that extends on catalog/product_list and replaces the function _getProductCollection.
If you want to know how to do that, please read this:
read this thread
In this new block you add this function:
protected function _getProductCollection()
{
$category_ids = $this->getCategoryIds();
$productCollection = Mage::getModel('catalog/product')
->getCollection()
->addStoreFilter()
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addUrlRewrite()
->joinField(
'category_id', 'catalog/category_product', 'category_id',
'product_id = entity_id', null, 'left'
)
->addAttributeToFilter('category_id', array(
array('in' => array($category_ids)),
));
return $productCollection;
}
EDIT:
First, forget about the custom module. This is magento best pratice, since we dont want to edit the core. We will get back to that later.
You're block type now is core/template. The function getProductCollection doesn't exist in the block core/template.
Have a look in this folder: app/code/mage/core/block/template.php
So you have to reference to another block. Ideally you want to create a custom module for this that extents the block type catalog/product_list. But as I said earlier, well get back to that later.
In the block catalog/product_list
( app/code/mage/catalog/product/list.php
) is the function _getProductCollection(). This is the function that every catalog pages uses to get the product collection. This is also the function you want to use. So change core/template
with catalog/product_list
.
Replace the function _getProductCollection()
with the function I pasted above. You will see that it works!
Now that you know that the new function that you made works, you want to put this code in a new custom block. You do that to create a module with a block. Read this thread carefully to create a new block:
Stackexchange link to create a custom block
Reason for creating a new block is that we dont want to edit the core of magento. When you update magento to the newest version the changes you have done are gone. Also its hard to keep track of the changes being done.
I hope you now better understand the magento block system!
Best Answer
For that you need to create on block file in your custom module,for example here I create one block file and in that file, you set custom category collection.
now call phtml with this block name like,
and get the custom collection in your phtml.