您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程
ecshop任何页面调用指定商品分类下面精品商品的实现方法
听蓉2024-05-13Ecshop商城教程已有人查阅
导读ECSHOP商城任何页面调用指定商品分类下面精品商品,比如首页,商品页面,分类页面,调用指定商品分类下面的精品商品。
ECSHOP商城任何页面调用指定商品分类下面精品商品,比如首页,商品页面,分类页面,调用指定商品分类下面的精品商品。
例如:商城首页和商品页面
1,打开index.php或者goods.php 在最下面?>前面加
/** * 获得cat_id精品列表。 * * @access private * @param integer * @return array */ function index_get_cat_id_goods_best_list($cat_id, $num) { $sql = 'Select g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price, g.promote_price, ' . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " . "g.is_best, g.is_new, g.is_hot, g.is_promote " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_best = 1 AND (" . $cat_id . " OR " . get_extension_goods($cat_id) .")"; $cats = get_children($cat_id); $where = !empty($cats) ? "AND ($cats OR " . get_extension_goods($cats) . ") " : ''; $sql .=$where." LIMIT $num"; $res = $GLOBALS['db']->getAll($sql); $goods = array(); foreach ($res AS $idx => $row) { $goods[$idx]['id'] = $row['article_id']; $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]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); $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]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); $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; }
2. index.php 的 $smarty->assign('shop_notice', $_CFG['shop_notice']); // 商店公告
下面增加:
$smarty->assign('cat_id8_best_goods', index_get_cat_id_goods_best_list(8,9));//注意这里的8是商品分类id,商品数量9
3.商城首页增加:
<!-- {foreach from=$cat_id8_best_goods item=goods name=no}--> <div class="line"> <div class="item"> <span class="no">{$smarty.foreach.no.iteration}</span> <p class="pic"><a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="B_blue" /></a></p> <p class="name"> <a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.name|escape}</a></p> <p class="price"> <span class="goodsPrice"> <!-- {if $goods.promote_price neq ""} --> {$goods.promote_price} <!-- {else}--> {$goods.shop_price} <!--{/if}--> </span> </p> </div> </div> <div style="clear:both"></div> <!-- {/foreach} -->
例如:商城首页和商品页面
1,打开index.php或者goods.php 在最下面?>前面加
/** * 获得cat_id精品列表。 * * @access private * @param integer * @return array */ function index_get_cat_id_goods_best_list($cat_id, $num) { $sql = 'Select g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price, g.promote_price, ' . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " . "g.is_best, g.is_new, g.is_hot, g.is_promote " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_best = 1 AND (" . $cat_id . " OR " . get_extension_goods($cat_id) .")"; $cats = get_children($cat_id); $where = !empty($cats) ? "AND ($cats OR " . get_extension_goods($cats) . ") " : ''; $sql .=$where." LIMIT $num"; $res = $GLOBALS['db']->getAll($sql); $goods = array(); foreach ($res AS $idx => $row) { $goods[$idx]['id'] = $row['article_id']; $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]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); $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]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); $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; }
2. index.php 的 $smarty->assign('shop_notice', $_CFG['shop_notice']); // 商店公告
下面增加:
$smarty->assign('cat_id8_best_goods', index_get_cat_id_goods_best_list(8,9));//注意这里的8是商品分类id,商品数量9
3.商城首页增加:
<!-- {foreach from=$cat_id8_best_goods item=goods name=no}--> <div class="line"> <div class="item"> <span class="no">{$smarty.foreach.no.iteration}</span> <p class="pic"><a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="B_blue" /></a></p> <p class="name"> <a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.name|escape}</a></p> <p class="price"> <span class="goodsPrice"> <!-- {if $goods.promote_price neq ""} --> {$goods.promote_price} <!-- {else}--> {$goods.shop_price} <!--{/if}--> </span> </p> </div> </div> <div style="clear:both"></div> <!-- {/foreach} -->
本文标签:
很赞哦! ()
相关教程
图文教程
ecshop后台登录超时的解决方法
在后台编辑产品经常由于时间长而超时,可以在登录的时候,勾起“请保存我这次登录信息”就可以不提示超时了,或者直接修改\admin\templates\login.html,让页面默认选中这一项!
ecshop商城首页商品显示已销售数量的实现方法
ECSHOP商城首页商品显示已销售数量修改教程,步骤一:打开文件 includes/lib_goods.php在该文件的末尾添加如下代码片段
ecshop清空购物车时怎么加上提醒
经常有朋友反应,他们在ecshop购物车中修改数量,点“更新购物车”时,经常不小心点中了“清空购物车”,一下子,所以的产品都没了
ecshop模板css高级应用iconfont矢量图替换方法
矢量图标替换教程首入,这一段代码 注释掉,如下;然后在 style.css 很底部 添加 以下代码;这样就可以了刷新页面看效果了。
相关源码
-
(PC+WAP)盆栽绿植观赏植物花卉租赁免费pbootcms网站模板为花卉盆栽租赁、园林绿化企业打造的PbootCMS网站模板,采用较新内核开发,PC与移动端数据实时同步。通过清新自然的视觉设计,精准展现植物养护、花卉展示等业务场景,帮助用户快速建立专业级行业网站。查看源码 -
帝国CMS7.5二次元COS漫展网站模板源码免费下载本模板基于帝国CMS 7.5版本深度开发,为二次元文化分享领域设计。采用UTF-8编码,支持中文内容展示,特别适用于COSPLAY作品展示、漫展信息发布等二次元相关内容的网站建设。模板结构清晰,布局合理,充分考虑了二次元用户群体的浏览习惯和审美需求。查看源码 -
pbootcms网站网络公司个人作品展示类网站源码(自适应)为网站建设公司、网络服务企业打造的响应式门户解决方案,基于PbootCMS内核深度开发。采用前沿自适应架构,无缝适配手机端交互与PC端展示需求。查看源码 -
粉色家政月嫂保姆公司pbootcms网站模板(PC+WAP)为家政服务、月嫂保姆企业打造的营销型解决方案,基于PbootCMS内核开发,采用温馨粉色主题传递行业温度。PHP7.0+高性能架构支持SQLite/MySQL双数据库查看源码 -
(自适应)中英双语配线器材扎带线卡网站pbootcms模板免费下载为线缆管理、电气配线领域打造的响应式网站模板,采用PbootCMS内核开发,可快速搭建企业级产品展示平台,数据实时同步管理。查看源码 -
(自适应)电梯扶梯升降梯行业pbootcms企业网站模板(自适应手机版)响应式电梯扶梯类pbootcms模板 电梯生产企业绿色企业网站源码下载PbootCMS内核开发的网站模板,该模板适用于电梯、扶梯类等企业,查看源码
| 分享笔记 (共有 篇笔记) |