0
votes

I have a problem in view the products on the home page. more precisely, if I use this code:

$_productCollection=$this->getLoadedProductCollection();    

I get the message "There are no products matching the selection."

but if I replace the above code with this:

$_productCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('visibility', 4)->addAttributeToFilter('status', 1)->load();    

I then displays all the products in the catalog, even though I specified on the home page, in this way, what category see more:

{{block type="catalog/product_list" category_id="24" template="catalog/product/list-home.phtml"}}    

how can I fix it?

P.S. I have the same problem when I select a product category from the navigation bar.

Thanks in advance for the help.

**** EDIT ****

code that I use inside the CMS home page is:

{{block type="catalog/product_list" category_id="24" template="catalog/product/list-home.phtml"}}    

code that use the file list-home.phtml is this:

<?php    
$_productCollection=$this->getLoadedProductCollection();    
$_helper = $this->helper('catalog/output');?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount();?>
<ul class="products-grid row">
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php /* if ($i++%$_columnCount==0): ?>
<ul class="products-grid row">
<?php endif */ ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first
<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>  col-sm-4 col-xs-6"> 
<div class="item-container img-thumbnail">
<div class="item-flipper">
<div class="item-front">
<!-- front content -->
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(250,310); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="img-responsive" /></a>
</div>
<div class="item-back">
<!-- back content -->
<div class="book-info">
<div class="h4"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></div>
<div class="short-description"><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></div>
</div>
<p><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="btn btn-block btn-success"><?php echo $this->__('Book Details')></a></p>
</div>
</div>
</div>
<h3 class="panel-title 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></h3>
<div class="pull-left"> <?php echo $this->getPriceHtml($_product, true) ?> </div>
<div class="pull-right">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-warning btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><?php echo $this->__('Add to Cart') ?></button>
<?php else: ?>
<p class="btn btn-alert availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
</li>
<?php if ($i==6) break; ?>
<?php /*  if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif */ ?>
<?php endforeach ?></ul>
</div>
<?php endif; ?>    

with the code above can not I see any product. if I replace the code that I said at the beginning, then I can see all the products, but I would like to display only those belonging to the category that I specified in the code of the home page.

I can not understand where I'm wrong.

3
I tried to make the correction that I have suggested, but the result does not change.fr4nc3
I will change the initial post with more information, because I realized that I have not explained wellfr4nc3

3 Answers

0
votes

You can use this code

{{block type="catalog/product_list" name="catalog.product.list" alias="products_homepage" category_id="5" template="catalog/product/list.phtml"}}
0
votes

We can set this easily by going to Admin panel > CMS > Home , and add the below code in it.

{{block type="catalog/product_list" category_id="1" template="catalog/product/list.phtml"}}

Where category_id = 1 is category you want to display on home page. You can get category id from category page in Magento's admin.

Hope this will help.

0
votes

Try this to set the category page as homepage.., Go to Admin System->Configuration->Web->Default pages(tab)->Default web url In that field give the category Id of the page you want to display it in home page as catalog/category/view/**id**