- 浏览: 13630062 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
magento 首页添加随机产品 add a Random Featured Product list on home page in Magento
want to show products from a specific category on your home page you can do this simply with
{{block type="catalog/product_list" category_id="12" template="catalog/product/list.phtml"}}
on your home page which works fine.. however, if you want these products to be randomly selected you hit problems.
The obvious thing to try is
{{block type="catalog/product_list_random" category_id="12" template="catalog/product/list.phtml"}}
however, this displays random products from EVERY category!!
The reason for this is that the file random.php does not work as advertised so we need to create a new version that does. We do not want to break upgrade compatibility so create the following directory structure.
in app/code/local create Mage/Catalog/Block/Product/List
eg mkdir -p Mage/Catalog/Block/Product/List
In your new List directory create the following file called Random.php
<?php class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List { protected function _getProductCollection() { if (is_null($this->_productCollection)) { $categoryID = $this->getCategoryId(); if($categoryID) { $category = new Mage_Catalog_Model_Category(); $category->load($categoryID); // this is category id $collection = $category->getProductCollection(); } else { $collection = Mage::getResourceModel('catalog/product_collection'); } Mage::getModel('catalog/layer')->prepareProductCollection($collection); $collection->getSelect()->order('rand()'); $collection->addStoreFilter(); $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 3; $collection->setPage(1, $numProducts)->load(); $this->_productCollection = $collection; } return $this->_productCollection; } }
To call this on your home page open your Home page in CMS > Static Pages and in Content add
{{block type="catalog/product_list_random" category_id="YOUR_CATEGORY_ID" template="catalog/product/list.phtml" column_count="4" num_products="12"}}
Create a new hidden category and add the products you wish to randomly select from. Find the category ID of this category and enter this number in the above place marker.
You will find that although you are seeing the Category display tool bar (drid view / list view / show.. etc) it has no effect on the layout. the default layout is 3 x 3 grid which is where column_count=”4″ comes into play. Alter this to meet your themes needs. Same goes for num_products=”12″.
And that is that.
Don’t want to be looking at the grid.. hide it. (evil hack alert)
Add
<style type="text/css"> .toolbar {display:none;} </style>
at the top of your Content area on the homepage CMS. this will hide the tool bar for just the homepage.
References:
Thanks to mac75a here :
http://www.magentocommerce.com/boards/viewthread/72319/ and andytm here:
http://www.magentocommerce.com/boards/viewthread/72319/
结合以下内容:
- Create a category to contain the featured products. Call it e.g.
“Featured
” or “Home Pag
e”. Set “Is Active
” to No
. That way, it won’t
display in the catalog menu. - After saving the category, please note
what ID it gets. You can see it in the last part of the URL
. If the URL
ends with catalog_category/edit/id/8/
, the ID is 8
. On later version, the ID is next to the category name:
Add products for the home page to the new category. - Edit the Home Page (CMS → Manage Pages → Home Page ) and add the following content, where 8 should be replaced by your category ID:
{{block type="catalog/product_list" category_id="8" template="catalog/product/list.phtml"}}
If your product/list.html references $this→getColumnCount() you can vary the column count (e.g. 4 columns) from the default (3) displayed by using:
{{block type="catalog/product_list" column_count="4" category_id="8" template="catalog/product/list.phtml"}}
Although displaying more than 3 columns in your template would likely require additional CSS /layout changes as well.
If you want a view that is different from the category lists, you can copy and modify list.phtml and change the path above. Following steps is an example.
Add Bestsellers to Home Page using the best-selling box of Blue Theme |
In Blue Theme, there is a sample HTML code in the content box (Admin → CMS → Manage Pages → Home Page ) that displays a list of Best Selling Products. You can easily modify list.phtml to reuse the skin of the best-selling box. Adding featured products to Home Page is a matter of clicking to select the required products in the category (Admin → CMS → Manage Categories → Category Products tab ) as outlined in the above method and there is no need to mess with the HTML code in the CMS .
1. Copy the following code to your preferred text editor
<?php $_productCollection=$this->getLoadedProductCollection() ?> <?php if(!$_productCollection->count()): ?> <div class="note-msg"> <?php echo $this->__('There are no products matching the selection.') ?> </div> <?php else: ?> <div class="box best-selling"> <?php $_collectionSize = $_productCollection->count() ?> <table border="0" cellspacing="0"> <tbody> <?php $i=0; foreach ($_productCollection as $_product): ?> <?php if($i++%2==0): ?> <tr> <?php endif; ?> <td> <a href="<?php echo $_product->getProductUrl() ?>" > <img class="product-img" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(95, 95); ?>" width="95" height="95" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /> </a> <div class="product-description"> <p><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></p> <?php echo $this->getPriceHtml($_product, true) ?> <?php if($_product->getRatingSummary()): ?> <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> <?php endif; ?> <?php echo nl2br($_product->getShortDescription()) ?> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><small><?php echo $this->__('Learn More') ?></small></a> </td> <?php if($i%2==0 || $i==$_collectionSize): ?> </tr> <?php endif; ?> <?php endforeach ?> <script type="text/javascript">decorateGeneric($$('tr'), ['last', 'odd', 'even']);</script> </tbody> </table> </div> <?php endif; //$_productCollection->count() ?>
2. Name it homelist.phtml and save it in location app/design/frontend/default/blue/template/catalog/product
, create the folders where necessary
3. Edit the Home Page (CMS → Manage Pages → Home Page ) and add the following content, where 19 should be replaced by your category ID:
<h3>Best Selling Products</h3> {{block type="catalog/product_list" category_id="19" template="catalog/product/homelist.phtml"}}
If you follow this Wiki, you’ll notice that the breadcrumbs in the Product Page include the inactive category in the middle (Home/Inactive/Product
) and if you click on the category, you’ll be served with a 404. Following steps show you how to hide the inactive category.
-
Rename your category by adding a prefix ‘0’(Admin → Catalog → Manage Categories → select the inactive category → Name), if your category name is Bestsellers, then rename it 0Bestsellers. This only works if names of other active categories do not start with ‘0’.
-
Edit breadcrumbs.phtml located in
app/design/frontend/default/default/template/page/html
by adding this<?php if($_crumbInfo[’label’][0]!=’0’): ?>
to line 31 and this<?php endif; ?>
at line 44. (The line numbers are based on version 1.2.0.2) The complete code:
<?php if($crumbs && is_array($crumbs)): ?> <h4 class="no-display"><?php echo $this->__("You're currently on:") ?></h4> <ul class="breadcrumbs"> <?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?> <?php if($_crumbInfo['label'][0]!='0'): ?> <li class="<?php echo $_crumbName ?>"> <?php if($_crumbInfo['link']): ?> <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $_crumbInfo['title'] ?>"><?php echo $_crumbInfo['label'] ?></a> <?php elseif($_crumbInfo['last']): ?> <strong><?php echo $_crumbInfo['label'] ?></strong> <?php else: ?> <?php echo $_crumbInfo['label'] ?> <?php endif; ?> </li> <?php if(!$_crumbInfo['last']): ?> <li> / </li> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> </ul> <?php endif; ?>
-
Save the file to the Blue Theme directory here:
app/design/frontend/default/blue/template/page/html
(If you are using other theme, then save it in the corresponding directory.)
Please note: In order to make this work for more than one block of products with different category IDs on the same page, you need to add the following code at the end of your phtml file(s):
<?php //unset catalog to allow using template for multiple categories on single page Mage::unregister("_singleton/catalog/layer"); ?>
Alternative way: |
|
If you are on 1.4 or greater or 1.7EE or greater then this post is no longer valid as magento has moved to using widgets. You can find a featured product commercial widget here: http://www.magewidgets.com/featured-products-widget.html
If you want more in depth way, try to view this post: http://inchoo.net/ecommerce/magento/featured-products-on-magento-frontpage/
If you’re using Magento v1.1.5 or later, you might want to use these code snippets instead: http://www.magentocommerce.com/boards/viewthread/4780/P15/#t44262 This approach uses core functions instead of using Zend DB to figure out how to build a query statement.
from: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/cms_and_home_page/add_featured_products_to_home_page
中文参考:
1. http://www.hellokeykey.com/magento-home-products/
2. http://sjolzy.cn/Add-New-products-in-the-Magento-CMS-Page-with-paging.html
3. http://www.hellokeykey.com/magento-change-product-list-display/
发表评论
-
Magento: 后台显示图片不能找到 Image file was not found on product tab
2016-08-30 02:22 2880I was uploading some images f ... -
理解WordPress的PingBack和TrackBack
2016-08-26 02:21 5667pingback和trackback的功 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(四)
2016-06-07 11:40 981自上一篇之后,5天过去了,这篇文章总算是挤出来了... 其实 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(三)
2016-06-07 11:41 1999原则上WDCP安装好了,就可以直接使用了,FTP、MySQL ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(二)
2016-06-07 01:33 948上一篇讲到,主机正常运转了。但是此时如果直接访问公网IP是 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(一)
2016-06-07 01:31 21547现在小站唯一的流量都靠AWS这个关键词了,刚好要用AWS重新 ... -
零基础 Amazon Web Services (AWS) 入门教程 (列表)
2016-06-07 01:32 2032在 Amazon Web Services 上托 ... -
Magento 1.9:新订单通知 Admin Order Notifier
2016-06-02 02:48 798Here is a little Mag ... -
Magento 1.9.X 系列教程
2016-05-14 02:44 2243Magento安装下载教学: Magento教程 1 ... -
Magento: 产品页面下jquery change函数失效 Call javascript function onchange product option
2016-05-05 06:39 1693明显的原因是change函数跟magento默认的oncha ... -
Magento: 判断是否为手机浏览 Optimise Web's Mobile Detect Class for Magento
2016-04-29 07:01 1120项目地址:Optimise Web's Mobile Det ... -
Magento: Gird 和 form 区域 Module Development Series – Magento Admin Module
2016-04-28 02:39 633In this tutorial, we are goi ... -
Magento: addAttributeToFilter 和 addFieldToFilter 的区别 Difference between addAttri
2016-04-28 02:34 982addAttributeToFilter is use ... -
Magento: 后台获取menu链接 Getting the admin panel urls
2016-04-28 02:34 733The url for customer page in t ... -
Magento : 调用文件上传 upload file frontend
2016-04-27 01:25 1315bool mkdir ( string $pathname ... -
Magento: 自定义用户登录导向页面 Redirect Customer to Previous Page After Login
2016-04-26 02:45 1816Configuration Settings – L ... -
Magento: 代替flash上传 How to disable Flash uploader in Magento (product images and
2016-04-06 05:04 10831. 替换产品页flash上传按钮 - 使用 Du ... -
Magento: 在客户账户中添加自定义链接 My Account Add Link
2016-04-05 14:05 1194This extension add new link an ... -
Magento: 根据产品属性加载产品信息 Load A Category or Product by an Attribute
2016-03-26 01:35 894Load a Product by ID <?ph ... -
Magento模块开发之数据库SQL操作方法说明
2016-03-26 01:31 1290今天主要来看Magento中的Mysql4/Resource ...
相关推荐
NULL 博文链接:https://justcoding.iteye.com/blog/2100394
magento程序添加多个表运费,可以自行设置运费计算公式
Chapter 1, Installing Magento 2 on Apache and NGINX, is a totally different ballgame compared to Magento 1. Where Magento 1 could be installed through FTP or SSH, Magento 2 is installable only via the...
Magento 2 Beginners Guide by Gabriel Guarino English | 14 Mar. 2017 | ASIN: B01MS81BQX | 442 Pages | AZW3 | 31....He is also a moderator in Magento forums, and he is a frequent speaker at Magento events.
magento通过产品名称获取产品id提示代码
NULL 博文链接:https://hudeyong926.iteye.com/blog/1728074
magento站点首页显示新产品及产品数量,可在block块中设置产品数量
如何给产品描述里的关键字、字词批量添加链接?我想大家一直在的这样的插件。说实话,我也找了很久,也没有找到。可是由于需要,不得不自己开发一个这样的插件。并支持到Magento1.6.2 说明请查看:...
Chapter 1, Installing Magento 2 on Apache and NGINX, is a totally different ballgame compared to Magento 1. Where Magento 1 could be installed through FTP or SSH, Magento 2 is installable only via the...
magento通过mysql语句批量导出产品及其自定义属性
magento-stock-movements, Magento扩展,节省产品库存 节省你的Magento产品的库存 特性将库存移动保存在产品修改页面的新标签中安装 Magento 1.5. x, 1.6. x, 1.7. x, 1.8. x, 1.9.x使用 modgit 安装:$ cd/pat
Magento导入导出产品插件 编辑csv表格导入产品 Import Products categories multiple images and custom options 1 1 2 tgz 与官方插件一样
10 predefined block positions on each page Ability to place any block in any position by easily changing CMS page layout Unlimited number of blocks inside each position Unlimited number of content...
magento产品名称及描述批量修改sql
home-appliances magento 模板,magento 1.7 使用. 外贸站模板。
magento数据结构分析 magento数据字典
兼容Magento 1.9.x, 1.8.x, 1.7.x ,特点:完全自适应(响应式布局),自定义子主题,无限颜色,完全自定义,一键安装演示,小工具化横幅系统,颜色选择,MEGA菜单,多商店支持,自定义产品尺寸,黑白2个版本,AJAX...
Get a hands-on introduction to custom shipping and payment methods ☆ 出版信息:☆ [作者信息] Branko Ajzele [出版机构] Packt Publishing [出版日期] 2013年09月25日 [图书页数] 128页 [图书语言] 英语...
magento导入导出产品分类