Magento产品列表(按类别ID) [英] Magento Product Listing by Category ID
问题描述
我有一家magento(1.5)商店和一个wordpress(3.2)博客.
I have a magento (1.5) store and a wordpress (3.2) blog.
wordpress博客是主要站点和主页索引.
The wordpress blogs acts as the main site and the home-page index.
使用Mage-Enabler,我将wordpress和magento集成在一起,并且能够拉出结帐块,快速链接和所有文件.
Using Mage-Enabler, I have integrated wordpress and magento together and I am able to pull the checkout block, quick links and all the files.
我的问题是,我想在首页上显示最畅销的类别.我通常会使用CMS中的XML来执行此操作. 例如
My question is that I would like to display the top-sellers categories on the home-page. I would usually do this with the XML in the CMS. e.g.
{{block type="catalog/product_list" category_id="your_category_id" template="catalog/product/list.phtml"}}
但是在这种情况下这是不可能的,因为看不到商店主页,例如,当用户单击导航上的shop-online按钮时,它将带他们到显示所有类别和搜索的类别登陆页面.
But this is not possible in this instance as the store home-page is not seen e.g when a user clicks on the shop-online button on the navigation it takes them onto the category lander page showing all the categories and a search.
我的逻辑促使我通过PHP来做到这一点
My logic has lead me to do this via PHP e.g
<?php
$categoryId = 123; // a category id that you can get from admin
$category = Mage::getModel('catalog/category')->load($category_Id);
?>
...这将位于产品> list.phtml页面的副本中.
... this would be inside a copy of the product > list.phtml page.
是否可以通过PHP模板通过特定类别而不是管理员中的块类型XML将产品拉入列表中?
Is this possible to pull products in a list via a specfic category via PHP templates rather than the block types XML in the admin?
谢谢
Cameron
推荐答案
这应该做您需要做的事情:
This oughtta do what you need:
<?php
$categoryid = 12;
$category = Mage::getModel('catalog/category');
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $_product) { ?>
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" /></a> <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a>
<?php } ?>
这篇关于Magento产品列表(按类别ID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!