How do display products by category in CMS page in Magento?

你说的曾经没有我的故事 提交于 2019-12-05 06:42:33

问题


i have one page with the name "products". in this page i need to display all the items seperated by it's corresponding category name. the structure looks like below

category 1

item1   item2


category 2

item1 item2

how can i do this?


回答1:


{{block type="catalog/product_list" category_id="8" template="catalog/product/featured.phtml"}} 

add above code in cms page and add featured.phtml file in catalog/product and put this code

    <?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php if(!$_productCollection->count()): ?>
<div class="note-msg">
    <?php echo $this->__('There are no products matching the selection. Please provide a category ID.') ?>
</div>
<?php else: ?>

<?php // Grid Mode ?>


  <ul id="featured" class="jcarousel-skin-tango">

<?php $_collectionSize = $_productCollection->count() ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if($i++%4==0): ?>


                <?php endif ?>



             <li><a class="preview" rel="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300, 300); ?>" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(105, 105); ?>" width="105" height="105" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
                    </a> </li>

            <?php if ($i%4==0 && $i!=$_collectionSize): ?>

            <?php endif ?>


    <?php endforeach ?>


</ul>


<?php endif; ?>



回答2:


You can load a phtml inside a CMS using:

{{block type="catalog/product" template="catalog/product/view/custom.phtml"}}

Now for the categories you want to display the above structure, you can load them in the category model, and get all products in the custom.phtml



来源:https://stackoverflow.com/questions/10794046/how-do-display-products-by-category-in-cms-page-in-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!