Magento Daily New product show

Source: Internet
Author: User
Tags vars

http://blog.csdn.net/benben0503/article/details/8647020

1. Create newarrivals.php file:

[PHP]View Plaincopy
  1. <?php
  2. /**
  3. * This was the part of ' bmproducts ' module for Magento,
  4. * which allows easy access to product collection
  5. * With flexible filters
  6. */
  7. Class Bestmagento_bmproducts_block_product_newarrivals extends Mage_catalog_block_product_list
  8. {
  9. function Get_prod_count ()
  10. {
  11. //unset any saved limits
  12. Mage::getsingleton (' catalog/session ')->unslimitpage ();
  13. return (isset ($_request[' limit '))?  intval ($_request[' limit '): 48;
  14. }
  15. function get_cur_page ()
  16. {
  17. return (isset ($_request[' P '))?  intval ($_request[' P ']): 1;
  18. }
  19. /** 
  20. * Retrieve loaded Category Collection
  21. *
  22. * @return Mage_eav_model_entity_collection_abstract
  23. **/
  24. protected function _getproductcollection ()
  25. {
  26. $date = $_get[' Date '];
  27. $collection = Mage::getresourcemodel (' catalog/product_collection ');
  28. $collection->setvisibility (Mage::getsingleton (' catalog/product_visibility ')  Getvisibleincatalogids ());
  29. $collection = $this->_addproductattributesandprices ($collection)
  30. ->addattributetoselect (' created_at ')
  31. ->setorder (' created_at ', ' desc ')
  32. ->setpagesize ($this->get_prod_count ())
  33. ->setcurpage ($this->get_cur_page ());
  34. if (! Empty ($date))
  35. {
  36. $this->_data[' title ' = $date;
  37. $collection->getselect ()->where (' DATE (created_at) =? ',$date);
  38. }
  39. $this->setproductcollection ($collection);
  40. return $collection;
  41. }
  42. }


2, the background CMS list to add Page page, set design content is:

[HTML]View Plaincopy
  1. <reference name="Content">
  2. <block type="bmproducts/product_newarrivals" name="product_new" template=" Catalog/product/list.phtml ">
  3. <block type= "catalog/product_list_toolbar" name="Product_list_toolbar " template="catalog/product/list/toolbar.phtml">
  4. <block type="Page/html_pager" name="Product_list_toolbar_pager" />
  5. <action method="Setdefaultgridperpage"><limit>48</ limit></action>
  6. <action method="Addpagerlimit"><mode>grid</mode> <limit>48</limit></action>
  7. </block>
  8. <action method="Settoolbarblockname"><name>product_list_toolbar </name></action>
  9. </block>
  10. </Reference>


Without paging, you can set only the content items to:

[HTML]View Plaincopy
    1. {{block type="bmproducts/product_newarrivals" name= "newarrivals" title= "New Arrivals" template="Catalog/product/list.phtml"}}


3. Add the following code where you want to display the directory:

[PHP]View Plaincopy
    1. <div class="Support_left" >
    2. <div class="subitem" >
    3. <div class="title" >new arrivals</div>
    4. <?php
    5. $collection = Mage::getmodel (' catalog/product ')->getresourcecollection ()
    6. ->setorder (' created_at ', ' desc ');
    7. $collection->getselect ()->group (' CAST (created_at as Date) ';
    8. //$collection->getselect ()->group (' CAST (created_at as Date) '->limit (5);
    9. //echo $collection->getselect (); exit;
    10. $date = Array ();
    11. foreach ($collection as $val)
    12. {
    13. ?>
    14. <div class="Left_link" ><a href="/new_arrivals?date=<?php echo Date (" Y-m-d", Strtotime ($ val[' Created_at '));?> "rel=" nofollow "><?php echo date (" y-m-d ",strtotime ($val [ ' Created_at ')); ?></a></div>
    15. <?php
    16. }
    17. ?>
    18. </div>
    19. </div>

Magento Daily New product show

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.