Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Display only 3 related product on product view page, Magento?

I am displaying related products in content block of layout in product view page. My code in catalog.xml is:

<reference name="content">
     <block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>
</reference>

Now, all the related products are displayed in my product view page, but I want to display only 3 products, What should I do? Please, anybody can help ??

like image 954
madzacky Avatar asked May 10 '13 12:05

madzacky


People also ask

How do I remove related products in Magento 2?

You also need to go to all products page in backend and navigate what product you want to remove its related items. After that, unmark the checkbox of the product you want to remove and then save your selection.


1 Answers

You need to edit the template file catalog/product/list/related.phtml and limit the loop to only iterate through 3 products.

For example:

    ...
    <?php $i = 0; ?>
    <?php foreach($this->getItems() as $_item): ?>
        <?php if($i++ == 3) break; ?>
        ...
like image 191
zitix Avatar answered Oct 19 '22 23:10

zitix