I’m using a simple custom block to list products from a given category in the side bar. It works fine when called as
<block type="catalog/product_list" before="-" name="product.leftnav" as="product.leftnav" template="catalog/product/training_leftlist.phtml" />
On all pages except the product pages, where it causes an error (I get the item page with the 404 page below it).
Is there a better block type I should be using, or a different way of calling it on the product page?
Template file is:
<?php
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status',1)
->addStoreFilter()
->addCategoryFilter(Mage::getModel('catalog/category')->load(12));
$products->setPageSize(4)->setCurPage(1);
$_helper = $this->helper('catalog/output');
Then print the items with something like
if(count($products>0)) echo "<ul>";
foreach($products as $_product):?>
<li>
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
</li>
<?php endforeach;?>
<?php if(count($products>0)) echo "</ul>";?>
The answer turned out to use a different
block typefor each place.For the non-product pages
Then for the Product pages use
type="catalog/product_list_related". Remembering to remove the above too, e.g: