最近看到有朋友在论坛问到过此类问题,所以抽空写了下文。
) W8 A1 Z0 {# f5 P. t% d“在全部品牌页实现分页换页功能”,对商品品牌较多的朋友也许会有帮助。 1、打开brand.php- x1 S; C% ^3 Z% \. g' n* _9 y) B
找到
$ r z/ A! r' X1 ]9 j" Nif (empty($brand_id))% O, Z& j( @# t
{2 z0 ]/ H5 G* f
再找到
" l# C+ M+ I' w5 V5 zexit();
" u5 L, M4 O s X4 z' n6 J& [- S} 将这两者之间的代码全部替换为下面代码 ; i) F: ?# [* e) y* s/ q
6 X5 C0 {/ w2 q! U7 w
assign_template();, b2 I+ F, Q( P1 P$ |
$position = assign_ur_here('', $_LANG['all_brand']);6 y2 X1 l3 H6 z& F5 V
$smarty->assign('page_title', $position['title']); // 页面标题
( P1 o% C; r$ M/ @2 P $smarty->assign('ur_here', $position['ur_here']); // 当前位置1 W9 x8 t8 `7 Q- d
$smarty->assign('categories', get_categories_tree()); // 分类树
1 k$ f, }- \ v3 M. r. o! [$ J* W $smarty->assign('helps', get_shop_help()); // 网店帮助
8 B# h8 d/ K5 F2 v) W $smarty->assign('top_goods', get_top10()); // 销售排行
& W, z! ]" |, s/ O8 ~. a5 z& F
D$ g$ u7 c" m: n: {. v $sql = "SELECT count(*) as brand_count from ( select b.brand_id ".
b& j1 r( ]% c3 g* f/ r "FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".& E9 V8 f6 _* M, r
$GLOBALS['ecs']->table('goods') . " AS g ".6 d2 U% {+ P6 {6 p
"WHERE g.brand_id = b.brand_id AND is_show = 1 " .
! S5 ?, P- z9 @. `" V " AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
, }3 n0 A3 m9 @7 F. Z5 G4 u9 ~ "GROUP BY b.brand_id ) AS gb";. D7 P$ d* W1 u8 [
$brand_count=$GLOBALS['db']->getOne($sql); //品牌(含有商品的)数量
2 b1 l; H* S. n8 _ $page = !empty($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;9 B/ u( u% G; n
$size = 3;. c: e" L' v: T* e9 W% \
$max_page = ($brand_count> 0) ? ceil($brand_count / $size) : 1;
* ?$ O( Y8 U3 {: }( ` if ($page > $max_page) {$page = $max_page;}$ ^5 f( I& f* n& f$ f6 ?
$start=($page - 1) * $size; & _ j; i9 s0 [4 m- ?- i' N% z
$sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, b.brand_desc, COUNT(*) AS goods_num, IF(b.brand_logo > '', '1', '0') AS tag ".6 F6 ^5 T( P' t# Y" I
"FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".- q5 f% s0 g$ q1 @+ V
$GLOBALS['ecs']->table('goods') . " AS g ".
1 }( F4 o1 n" Z, [) C5 ~, t) m "WHERE g.brand_id = b.brand_id AND is_show = 1 " .9 G1 [' H- s+ ]: z
" AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
5 F" a/ @" l+ X7 ^+ a* d" X "GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC limit $start,$size";! k$ j1 d/ u# w7 S: c1 r1 X9 d
/ a% Q5 K' w. i' `9 P% t" X) Z $row = $GLOBALS['db']->getAll($sql);2 c6 t6 M) i, L4 R; f3 m
foreach ($row AS $key => $val); Q6 t, a) G5 T
{" p4 A7 t* A/ O' L: u- S8 O
$row[$key]['url'] = build_uri('brand', array('cid' => $cat, 'bid' => $val['brand_id']), $val['brand_name']);6 f% }) q R+ s7 f. Y
$row[$key]['brand_desc'] = htmlspecialchars($val['brand_desc'],ENT_QUOTES);
: @% B3 B' d& {; ? }9 ]% K2 u9 }, M- Q* I) e7 P, _+ G
$pager['search'] = array( );# n0 T1 e0 T o/ b. [& D
$pager = get_pager('brand.php', $pager['search'], $brand_count, $page, $size);
, H! \3 g1 X7 s8 Q: ` $pager['display'] = $display;/ V3 m% c- T5 ?3 C, `/ r& W
$smarty->assign('pager', $pager);2 R+ a# o% |, j0 _' t* [
$smarty->assign('brand_list', $row);
/ V! T0 X7 P v4 |. v $smarty->display('brand_list.dwt'); |
: P o ?+ d0 V8 ]+ y) X& x! U# C3 V- D% {0 `4 u
2、打开 模板文件 brand_list.dwt) \6 ]8 h. z" k3 J: Y) n5 ^
在你想要显示换页信息的地方加入下面代码2 g, Z5 X1 H7 t5 b- m
<!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem -->
) S! e1 X& p- T! W 如果你使用的是官方默认模板,那么在
+ V- y9 W4 N2 E, A2 g) x <div class="dashed"></div># h5 @0 f0 k0 k
这行代码下面加
8 O1 o! W/ w! t5 S5 ]) I/ k# v <!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem -->
' Z* P; A% F: a+ U0 O 比较合适。
7 V7 Z1 h% Q+ B y- C7 z! A# T |