magento随机显示产品-可在cms中调用
piaoling 2012-08-07 15:08:46
magento随机显示产品-可在cms中调用
在可以cms静态块中调用,可以以在产品页面插入,
1.建立phtml文件,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
http://gccde.com/<?php $chosen_category = Mage::getModel('catalog/category')->load($this->getCategoryId()); $_helper = $this->helper('catalog/output'); $_productCollection = $this->getLoadedProductCollection(); $number_of_products = $this->getNumProducts(); if (sizeof($_productCollection) < $number_of_products) { $number_of_products = sizeof($_productCollection); } $displayed_products = array(); foreach ($_productCollection as $_product) { $displayed_products[] = $_product; } $random_products = array(); if (sizeof($_productCollection) > 1) { $random_products = array_rand($displayed_products, $number_of_products); } else { $random_products = array('0'); } ?> http://gccde.com/<?php if(!$_productCollection->getSize()):?> <div class="note-msg"> <?=$this->__('There are no products matching the selection.')?> </div> http://gccde.com/<?php else:?> <div class="category-head"> <h2><?=$this->__('Featured products')?></h2> </div> http://gccde.com/<?php for ($i=0; $i < $number_of_products; $i++): ?> http://gccde.com/<?php $_product = $displayed_products[$random_products[$i]]; ?> http://gccde.com/<?php // Change from here for layout - currently as list //use app/design/frontend/YOUR PACKAGE/YOUR THEME/template/catalog/product/list.phtml //to copy grid of list layout (below is a direct copy of LIST layout from that file (list.phtml) //in other words -> copy the <ul></ul> "<ul class="products-grid">" from list.phtml //GRID NOT TESTED (should work in theory) ;) ?> <ol class="products-list" id="products-list"> <li class="itemhttp://gccde.com/<?php if( ++$_iterator == sizeof($_productCollection) ): ?> lasthttp://gccde.com/<?php endif; ?>"> http://gccde.com/<?php // Product Image ?> <a href="http://gccde.com/<?php echo $_product->getProductUrl() ?>" title="http://gccde.com/<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="http://gccde.com/<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170); ?>" width="170" height="170" alt="http://gccde.com/<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a> http://gccde.com/<?php // Product description ?> <div class="product-shop"> <div class="f-fix"> http://gccde.com/<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?> <h2 class="product-name"><a href="http://gccde.com/<?php echo $_product->getProductUrl() ?>" title="http://gccde.com/<?php echo $_productNameStripped; ?>">http://gccde.com/<?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2> http://gccde.com/<?php if($_product->getRatingSummary()): ?> http://gccde.com/<?php echo $this->getReviewsSummaryHtml($_product) ?> http://gccde.com/<?php endif; ?> http://gccde.com/<?php echo $this->getPriceHtml($_product, true) ?> http://gccde.com/<?php if($_product->isSaleable()): ?> <p><button type="button" title="http://gccde.com/<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('http://gccde.com/<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span>http://gccde.com/<?php echo $this->__('Add to Cart') ?></span></span></button></p> http://gccde.com/<?php else: ?> <p class="availability out-of-stock"><span>http://gccde.com/<?php echo $this->__('Out of stock') ?></span></p> http://gccde.com/<?php endif; ?> <div class="desc std"> http://gccde.com/<?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?> <a href="http://gccde.com/<?php echo $_product->getProductUrl() ?>" title="http://gccde.com/<?php echo $_productNameStripped ?>" class="link-learn">http://gccde.com/<?php echo $this->__('Learn More') ?></a> </div> <ul class="add-to-links"> http://gccde.com/<?php if ($this->helper('wishlist')->isAllow()) : ?> <li><a href="http://gccde.com/<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist">http://gccde.com/<?php echo $this->__('Add to Wishlist') ?></a></li> http://gccde.com/<?php endif; ?> http://gccde.com/<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?> <li><span class="separator">|</span> <a href="http://gccde.com/<?php echo $_compareUrl ?>" class="link-compare">http://gccde.com/<?php echo $this->__('Add to Compare') ?></a></li> http://gccde.com/<?php endif; ?> </ul> </div> </div> </li> </ol> http://gccde.com/<?php // END OF LAYOUT ?> http://gccde.com/<?php endfor;?> http://gccde.com/<?php endif;?> <p class="dalsi"><a href="<?=$chosen_category->getUrl()?>" title="<?=$this->__('More products from this category ...')?>"><?=$this->__('More products from this category ...')?></a></p> |
放入app/design/frontend/YOUR PACKAGE/YOUR THEME/template/catalog/product/中
在cms 或者是静态块中调用:
1 |
{{block type="catalog/product_list_random" num_products="5" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/random.phtml"}} |
ccs可以自定义
最近弄了一个 –如果添加Up-sells(向上销售)就取消随机获取,如果不添加Up-sells就随机出现产品!
发表评论(评论将通过邮件发给作者):