Hello everyone,
i try to show products of the specific category on homepage.
i had posted the code into the "CONTENT" of "PAGE"
Code: {{block type="catalog/product_list" column_count="4" category_id="4" template="catalog/product/list.phtml"}}
The reulst: it just showed the grey color as the same as following picture:
THANK YOU!
Hi,
You can try the following code -
$collection = $this->_productcollection->create() ->addAttributeToFilter('status', '1'); $collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds()); $collection = $this->_addProductAttributesAndPrices($collection) ->setPageSize($productCount); /* To display product by category id */ if($category_id=$this->getData("category_id")){ $category = $this->categoryRepository->get($category_id); $collection->addCategoryFilter($category); } $collection->getSelect()->order('rand()'); return $collection;
1 2 | {{block type="catalog/product_list" category_id="4" template="catalog/product/list.phtml"}} |
5. In case you want to control the number of columns in product listing, please use the following code:
1 2 | {{block type="catalog/product_list" column_count="4" category_id="4" template="catalog/product/list.phtml"}} |
Where the column_count value is the number of columns.
6. Navigate to System->Permissions->Blocks.
7. Click on the Add new block
8. Specify your Block Name, which is: catalog/product_list.
9. And allow the Block using the YES/No Dropdownlist: