One: Retrieve all the Categories
| The code is as follows |
Copy Code |
| <div class= "New-arrivals-menu" > <p class= "Jumbotext" >new arrivals</p> <!--get category--> <ul> <?php $category _collection = Mage::getmodel (' catalog/category ')->getcollection () ->setstoreid (1) ->addattributetoselect (' name ') ->addattributetoselect (' Url_path ') ->addattributetoselect (' is_active '); foreach ($category _collection as $key => $category) { if ($category->getid () = = ' 5 ' | | $category->getid () = = ' 8 ' | | | $category->getid () = = ' 9 ') { ?> <li> <a class= "menu-<?php echo $category->getid ();? > New-arrivals-menu-trigger "href=" <?php Echo $category->geturl ();? > "data-outfits-container=" outfits-<?php Echo $category->getid ();? > "><?php echo $category->geturlkey () ><?php echo $category->getname ();?> <span class=" Caret Hide "></span></a> <ul class= "Menu-sub" style= "Display:none;" > <?php if ($category->haschildren ()) {//Determine if there is a subdirectory Veric@dev 2602429109 $ids = $category->getchildren (); Extract subdirectory ID list Veric@dev 2602429109 $subCategories = Mage::getmodel (' catalog/category ')->getcollection (); $subCategories->getselect ()->where ("e.entity_id in ($ids)"); Extract the specified directory IDs list Veric@dev 2602429109 $subCategories->addattributetoselect (' name '); Specify lookup directory name Veric@dev 2602429109 $subCategories->load (); foreach ($subCategories as $item) { ?> <li class= "<?php echo $item->getid ()?>" style= "Margin-left:20px;color:rgb (255, 255, 255)" > <a href= "<?php echo $item->geturl ()?>" target= "_blank" ><?php echo $item->getname ();?>< Span class= "Caret" ></span></a></li> <?php}?> <?php}?> </ul> </li> <?php}?> <?php}?> </ul> </div> |
Second: Get the product under the category
| The code is as follows |
Copy Code |
| <!--get imgage--> <div class= "New-arrivals-outfits-container" > <a class= "new-arrivals-outfits outfits-5 loading" href= "Javascript:void" (0); "style=" Display:block; " > <?php $products = Mage::getmodel (' catalog/category ')->load (5)->getproductcollection (); $products->addattributetoselect (Array (' name ', ' id ', ' price ', ' url_key ', ' small_image ')); $products->addattributetofilter (' status ', 1); $products->addattributetofilter (' visibility ', 4); Catalog, search $products->setorder (' entity_id ', ' DESC '); ->getsetids (4); $products->getselect ()->limit (5); ->getselect ()->limit (4); $productsql = $products->getselectcountsql (); Print_r ($productsql); foreach ($products as $key => $product) { Print_r ($key). ' <br/> '; ?> helper (' Catalog/image ')->init ($product, ' small_image ') ->resize (202,270)?> " alt= "<?php Echo $this->htmlescape ($product->getname ())?>" onclick= "window.open (' <?php echo $product- >getproducturl ();? > ') "/> <?php}?> </a> |