在首页Magento1.9上显示一个CATEGORY及其产品 [英] Show a CATEGORY and its products on Homepage, Magento1.9

查看:185
本文介绍了在首页Magento1.9上显示一个CATEGORY及其产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在首页上显示带有其产品的类别. Magento内置了在首页上显示新产品的选项,我不知道如何在首页上显示不同的类别.例如,我已经创建了一个类别,并且想要在首页上显示该类别中的产品,如下所示:

I want to show a Category with its Products on homepage. Magento has built in option to show New Products on homepage and I have no idea about how to show different categories on homepage. For example I have created a category and I want to show the products in this category on homepage as below:

产品1 产品2 产品3

Product1 Product2 Product3

我尝试了以下代码(来自以前的帖子)

I have tried below code (from previous posts)

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

但这给了我下面的错误

Fatal error: Call to a member function getSortedChildren() on a non-object in C:\wamp\www\magento1901\app\design\frontend\rwd\default\template\catalog\product\list.phtml on line 134

我上面提到的代码显然是针对先前版本或Magento的.但是1.9.0.1版会出现错误.

Apparently code I mentioned above is for previous versions or Magento. However version 1.9.0.1 gives error.

请指导如何在首页上显示类别.谢谢

Please guide how to show categories on homepage. Thanks

推荐答案

对于magento 1.9中的新产品列表,请使用此

for new product list in magento 1.9 use this one

   {{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

或按类别列出

新的RWD设计具有两个用于产品列表的子模块.更多信息

The new RWD design has two child blocks for the product list.more info

<block type="core/text_list" name="product_list.name.after" as="name.after" /> 
<block type="core/text_list" name="product_list.after" as="after" />

您可以先在CMS主页中调用您的广告块,如下所示:

You can first call your block in CMS Homepage like below:

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

现在在您的catalog/product/list.phtml中找到第74行和133行

Now in your catalog/product/list.phtml find line no 74: and 133

找到此代码

<?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; ?>

替换为

<?php
if($this->getChild('name.after')):
    $_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; 
endif;
?>

第188行

将代码添加到

if($this->getChild('after')):

//code

endif;

这篇关于在首页Magento1.9上显示一个CATEGORY及其产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆