<?
Require_once 'app/MAGE. php ';
Mage: APP ('default ');
$ Category = Mage: GetModel ('catalog/Category ')-> load (3 );
$ Productcollections = $ category-> getproductcollection ();
$ Productcollections-> addattributetoselect ('name ');
Foreach ($ productcollections as $ productcollection ){
Echo $ productcollection-> getname ();
Echo "<br/> ";
}
?>
Magento's homepage is a static page implemented by CMS. I think if we modify magento's routers, magento will not be allowed to access the CMS page by default, but directly go to the product page. But I haven't tried it yet. We can also directly add a block on the CMS page to display the product on the CMS page:
First, log on to the background and go to CMS --- manage page.
Then, edit the currently enabled Home Page
{Block type = "catalog/product_list" category_id = "XX" template = "catalog/product/Homepage. phtml "}}
In this way, a certain type of products can be put on the homepage. However, users often say that they want to pick a few specific products and put them on the homepage. I never thought about it, because it was always possible to know it before, and I always thought about it from the programming perspective, I always want to add a filtering condition to the product/list block of magento, and it does. The implementation steps are as follows:
1. Before a user adds a product, add an attribute (such as show_on_homepage and the name can be customized) to the attributte set used by the user. This attribute type is set to yesno, when the value is yes, it is displayed on the homepage, that is, if you want to display this product on the homepage, set this to yes.
2. Create a module that contains only one block. Add code to the block to filter the product collection. Of course, you can also directly put this block under the corresponding directory of the catalog module and put the Template under the relevant topic directory template.
$ Products = $ product-> setstoreid ($ storeid)-> getcollection ()
-> Addattributetofilter ('show _ on_homepage', array ('yes' => true ))
Obviously, the above aspect must be done when a user adds a product at the end of the user. What if the user has already added many products? There is still a solution. Because the product list block can display a certain type of products, if you do not want to modify the code, you can set a new subclass, be sure not to set it to active (unless you want to see this class in the homepage menu ). Then pass the ID of this subclass to the product list block. Then, let the user select the product to which the subclass is to be placed on the homepage and specify these products under this class, this makes use of the features that a magento product can specify for multiple categories.