原创-只需要1个文件做2次开发
2016-07-07 15:03 来源:www.chinab4c.com 作者:ecshop专家
<?php /*1把这个my.php放在根目录下 2在includes/init.php里面 加上require(ROOT_PATH . 'my.php');*/ /** * 获得指定分类下的推荐商品 * * @accesspublic * @paramstring$type 推荐类型,可以是 best, new, hot, promote 一定要加'' 比如 'new' * @paramstring$cats 分类的ID * @paraminteger$brand品牌的ID * @paraminteger$min商品价格下限 * @paraminteger$max商品价格上限 * @paramstring$ext商品扩展查询 * @returnarray $cats 分类id 只能是 单独一个ID $num 文章数量 可以是 1(代表1篇文章)也可以是 '1,2'(1代表从1+1位置开始2代表2-1篇文章) 如果空则调用 后台 网站配置里 的设置 模板里调用 <?php $this->assign('cat_goods6',get_category_recommend_goods_my('new',6));? > <!--{foreach from=$cat_goods6 item=goods}--> */ function get_category_recommend_goods_my($type = '', $cats = '', $num = '', $brand = 0, $min =0,$max = 0, $ext='') { $brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : ''; $price_where = ($min > 0) ? " AND g.shop_price >= $min " : ''; $price_where .= ($max > 0) ? " AND g.shop_price <= $max " : ''; $sql ='SELECT g.goods_id,g.cat_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON c.cat_id = g.cat_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . $brand_where . $price_where . $ext; //$num = 0; $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion'); if (empty($num))//如果空则调用 { $cat_num = get_library_number($type2lib[$type]); //后台 网站配置里 的设置 } else { $cat_num = $num; } switch ($type) { case 'best': $sql .= ' AND is_best = 1'; break; case 'new': $sql .= ' AND is_new = 1'; break; case 'hot': $sql .= ' AND is_hot = 1'; break; case 'promote': $time = gmtime(); $sql .= " AND is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time'"; break; } if (!empty($cats)) { $sql .= " AND (c.parent_id in(" . $cats . ") OR " . get_extension_goods($cats) .")"; } $order_type = $GLOBALS['_CFG']['recommend_order']; $sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()'; $res = $GLOBALS['db']->selectLimit($sql, $cat_num); $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id']= $row['goods_id']; $goods[$idx]['name']= $row['goods_name']; $goods[$idx]['brief']= $row['goods_brief']; $goods[$idx]['brand_name']= $row['brand_name']; $goods[$idx]['short_name']= $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price']= price_format($row['shop_price']); $goods[$idx]['thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $idx++; } return $goods; } /** * 获得指定分类商品本级列表。 $cat_id 文章分类id 可以 单独一个ID 也可以多个ID比如('1,2,3,4') $cat_num 文章数量 可以是 1(代表1篇文章)也可以是 '1,2'(1代表从1+1位置开始2代表2-1篇文章) 模板里调用 <?php $this->assign('cat_goods_3',cat_goods_list_my('12,13,14,15',10));? > <!--{foreach from=$cat_goods_3 item=goods}--> */ function cat_goods_list_my($cat_id,$cat_num) { $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price, g.goods_thumb , g.goods_img, g.cat_id ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "WHEREg.cat_id in (".$cat_id .") ORDER by g.goods_id DESC LIMIT ".$cat_num ." "; $res = $GLOBALS['db']->getAll($sql); $goods = array(); foreach ($res AS $idx => $row) { $goods[$idx]['id']=$row['goods_id']; $goods[$idx]['name']=$row['goods_name']; $goods[$idx]['market_price'] =price_format($row['market_price']); $goods[$idx]['shop_price']=price_format($row['shop_price']); $goods[$idx]['thumb']= empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb']; $goods[$idx]['goods_img']= empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img']; $goods[$idx]['url'] = build_uri('goods' , array('gid' => $row['goods_id']), $row['goods_name']); } return $goods; } /** * 获得自定义的文章列表。 * * @accessprivate * @returnarray $cat_id 文章分类id 可以 单独一个ID 也可以多个ID比如('1,2,3,4') $cat_num 文章数量 可以是 1(代表1篇文章)也可以是 '1,2'(1代表从1+1位置开始2代表2-1篇文章) $article_type 文章重要性 普通0置顶1 模板里调用 <?php $this->assign('new_articles',get_new_articles_my(4,1,1));? > <!--{foreach from=$new_articles item=article name=article}--> */ function get_new_articles_my($cat_id,$cat_num,$article_type) { $sql = 'SELECT article_id, title,add_time, file_url, open_type, content, description ' . ' FROM ' . $GLOBALS['ecs']->table('article') . " WHERE is_open = 1 AND cat_id in (".$cat_id .") and article_type=".$article_type. ' ORDER BY article_id DESC LIMIT '.$cat_num; $res = $GLOBALS['db']->getAll($sql); $arr = array(); foreach ($res AS $idx => $row) { $arr[$idx]['id'] = $row['article_id']; $arr[$idx]['title'] = $row['title']; //我修改 $arr[$idx]['content'] = $row['content']; $arr[$idx]['description'] = $row['description']; $arr[$idx]['file_url'] = $row['file_url']; //我修改 $arr[$idx]['title'] = $row['title']; $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[$idx]['cat_name'] = $row['cat_name']; $arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); $arr[$idx]['url']= $row['open_type'] != 1 ? build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']); $arr[$idx]['cat_url']= build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']); } return $arr; } ?> |
回答:
后台 模板设置中可以选择 指定分类的商品!不妨一试! |
楼上说的对啊!!模版设置里面选择该商品分类不就OK了,干嘛弄得那么麻烦... |
最近更新
常用插件
- ecshop分类批量扩展插件
ecshop分类批量扩展插件,这个插件是ecshop插件里面比较核心的插件。我们...
- ecshop商品分类名称增加样
ecshop插件介绍:本插件可以方便在后台管理,为ecshop商品分类名称增加样...
- ecshop二次商品订购人信息
ecshop二次商品订购人信息填写插件,有时候给朋友送花,或者是送礼品的...
- ecshop2.7.1打印发货单插件
ecshop2.7.1打印发货单插件介绍:ecshop2.7.1和以前的ecshop版本不一样,ecs...
- ecshop二次开发详细页面生
插件介绍: ECSHOP系统,在很多时候,很多商品没有人购买,不但购买的人...
ecshop热门问答
ecshop热门资料
ecshop404未找到
ecshop凡人
ecshop横幅
ecshop试验
ecshopscript
ecshop售后服务
ecshopletao
ecshop首页调用留言
ecshop正式会员
ecshop添加图片
xslecshop
ecshop加价
ecshop打包
ecshop零食
ecshopJoomla
ecshop沉默寡言
ecshopfalsh
ecshop模板文件
ecshop单据
ecshop体育用品网错误
zencart
ecshop快车道
ecshop字型
ecshop容量 申请
ecshop兼容性
ecshoppriv
ecshop导航下拉
ecshop非洲
ecshop组合筛选
ecshop472