ECSHOP默认只能在后台模板设置中设置首页调用分类下商品,比较死板。
为了更好的设计调用分类商品,可使用以下方法自定义调用:
第一步:
找到打开 /includes/lib_goods.php
在末尾 ?> 前加入以下代码:
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
|
function
get_cat_id_goods_index_list(
$cat_id
=
''
,
$num
=
''
)
//申明$cat_id,$num函数
{
$sql
=
'Select g.goods_id, g.cat_id,c.parent_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, "
.
"g.is_best, g.is_new, g.is_hot, g.is_promote "
.
'FROM '
.
$GLOBALS
[
'ecs'
]->table(
'goods'
) .
' AS g '
.
'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 "
.
$sql
.=
" AND (c.parent_id ="
.
$cat_id
.
" OR g.cat_id = "
.
$cat_id
.
" OR g.cat_id "
. db_create_in(
array_unique
(
array_merge
(
array
(
$cat_id
),
array_keys
(cat_list(
$cat_id
, 0, false))))) .
")"
.
"order by g.cat_id desc"
;
//cat_id降序排列
$sql
.=
" 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
;
}
|
第二步:
打开根目录下的 index.php
查找:
1
|
$smarty
->assign(
'shop_notice'
,
$_CFG
[
'shop_notice'
]);
// 商店公告
|
在这段代码后面,也就是下一行添加以下代码:
1
|
$smarty
->assign(
'cat_id1_index_goods'
, get_cat_id_goods_index_list(1,8));
//首页调用分类1下的8个商品
|
第三步:
打开/themes/default/index.dwt
在需要的地方添加以下代码:
1
2
3
4
5
6
7
8
|
<!--{
foreach
from=
$cat_id1_index_goods
item=goods}-->
<a
class
=
"first"
href=
"{$goods.url}"
target=
"_blank"
>
<img title=
"{$goods.name|escape:html}"
alt=
"{$goods.name|escape:html}"
width=
"220"
height=
"220"
src=
"{$goods.goods_img}"
/>
<p
class
=
"title"
title=
"{$goods.name|escape:html}"
> {
$goods
.name|escape:html} </p>
<p
class
=
"price"
> <span
class
=
"label"
>原价:</span><del>{
$goods
.market_price}</del></p>
<p
class
=
"price qz-price"
><span
class
=
"label"
>现价:</span><em>{
$goods
.shop_price}</em></p>
</a>
<!-- { /
foreach
}-->
|
如果首页需要重复多次调用,只需重复第二步代码即可。