Magento call all categories and the product program under their classification

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.