Question

I have researched on this issue about Magento 1.9 not adding the category to the home page. So, I ended up adding:

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="15" template="catalog/product/list.phtml"}}

To the home page content. It also shows up on the home page BUT: only with 1 product out of 5. Why is that and can this be changed?

I am still very new to Magento and I haven't changed anything at the layout bit. I have seen this post: Same problem, but no one has answered (and I can't comment on it), I have followed these steps - but all of it didn't work.

Was it helpful?

Solution

Are you using the rwd theme from Magento 1.9? If so, the problem might be in the catalog/product/list.phtml template file.

In catalog/product/list.phtml from the rwd theme the following code

from line 133 to 140

<?php $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren(); foreach($_nameAfterChildren as $_nameAfterChildName): $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName); $_nameAfterChild->setProduct($_product); ?> <?php echo $_nameAfterChild->toHtml(); ?> <?php endforeach; ?>

and from line 178 to 186

<?php //set product collection on after blocks $_afterChildren = $this->getChild('after')->getSortedChildren(); foreach($_afterChildren as $_afterChildName): $_afterChild = $this->getChild('after')->getChild($_afterChildName); $_afterChild->setProductCollection($_productCollection); ?> <?php echo $_afterChild->toHtml(); ?> <?php endforeach; ?>

will cause errors if you add the block in the layout without the children blocks 'name.after' and 'after'.

If you want this to work on your home page you should create a new template in the theme, for example catalog/product/list_home.phtml, and copy the code from catalog/product/list.phtml but delete the code from the lines I indicated. You should then use the new template in the home page block:

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="15" template="catalog/product/list_home.phtml"}}

OTHER TIPS

Remove those lines from catalog/product/list.phtml

<?php
    //set product collection on after blocks
    $_afterChildren = $this->getChild('after')->getSortedChildren();
    foreach($_afterChildren as $_afterChildName):
        $_afterChild = $this->getChild('after')->getChild($_afterChildName);
        $_afterChild->setProductCollection($_productCollection);
    ?>
    <?php echo $_afterChild->toHtml(); ?>
<?php endforeach; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top