最近看到有朋友在论坛问到过此类问题,所以抽空写了下文。; g4 T4 i) c3 Y( v+ t$ ~- |
“在全部品牌页实现分页换页功能”,对商品品牌较多的朋友也许会有帮助。 1、打开brand.php+ K$ H" W* e$ _, ^
找到
% O9 i9 B. e0 I' _" gif (empty($brand_id))' [/ j1 S3 ^& e" l0 [6 X- a
{' x8 u. z& H4 P1 N
再找到+ q( c) L" p4 V
exit();1 a9 F+ T+ p- Y. h
} 将这两者之间的代码全部替换为下面代码 : A1 e, \& o% x9 d0 ^3 ^
5 t+ T7 t$ N2 V8 f v
assign_template();+ U* ?+ E' t: h3 t, X( U, y
$position = assign_ur_here('', $_LANG['all_brand']);, [$ T7 ~# ?& R- ?, H% B
$smarty->assign('page_title', $position['title']); // 页面标题5 D) n2 v8 G2 a, I: V0 x0 d& S: }
$smarty->assign('ur_here', $position['ur_here']); // 当前位置3 l( b% P N/ B1 L/ Z1 N: F0 T) B
$smarty->assign('categories', get_categories_tree()); // 分类树) G) W6 p2 h; t. W' j1 c0 Y3 L
$smarty->assign('helps', get_shop_help()); // 网店帮助& P, m. A8 i1 g R8 k4 i
$smarty->assign('top_goods', get_top10()); // 销售排行
& \2 k# B* X# X( x
4 @2 h5 \6 L& k $sql = "SELECT count(*) as brand_count from ( select b.brand_id ".
$ A8 @& R: o4 d. U1 P! R "FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".
+ W- t$ A' }3 s$ a5 w5 z8 u $GLOBALS['ecs']->table('goods') . " AS g ".
$ |! }. F* Z) A "WHERE g.brand_id = b.brand_id AND is_show = 1 " .9 n2 p* S _0 o$ e5 B+ |7 h
" AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".% X# I6 r2 N! L% }
"GROUP BY b.brand_id ) AS gb";
" k* ~; j3 E9 ~ $brand_count=$GLOBALS['db']->getOne($sql); //品牌(含有商品的)数量
; a- _4 E1 i% ^5 q) p $page = !empty($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;+ t' T3 i$ O8 M
$size = 3;4 Y* o% n- ^6 i6 ~0 T' i3 t" N
$max_page = ($brand_count> 0) ? ceil($brand_count / $size) : 1;" b s, K8 D7 G$ S; B2 K+ {
if ($page > $max_page) {$page = $max_page;}" G& U4 b% z! @- m, i4 A9 f9 m
$start=($page - 1) * $size; 4 z; h7 O* m3 U( b8 v
$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 "./ \, g6 ?: I3 F( _
"FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".
% d4 B1 ?% T/ K# {0 C: f8 E $GLOBALS['ecs']->table('goods') . " AS g ".) F( h" n9 X! \5 y+ L5 M# Y* `/ E) e
"WHERE g.brand_id = b.brand_id AND is_show = 1 " .
! z" m* B, h6 F* m! {2 U " AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
# i2 { T/ N0 ], K7 r7 ] "GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC limit $start,$size";
3 R# H5 F4 e( T0 U( u4 [3 | 1 g4 u- ?' D% o6 h" e
$row = $GLOBALS['db']->getAll($sql);# D0 ~* u/ X4 _' T+ |
foreach ($row AS $key => $val)
$ [1 m1 I) v( w {6 l7 @6 A8 t$ x% s( |
$row[$key]['url'] = build_uri('brand', array('cid' => $cat, 'bid' => $val['brand_id']), $val['brand_name']);
, M* v7 a' [5 N% C $row[$key]['brand_desc'] = htmlspecialchars($val['brand_desc'],ENT_QUOTES);
}8 L) s: o4 [' A0 Q/ @! o }' K* N" f5 Z2 b
$pager['search'] = array( );: K) E: y8 a( ^- g+ t9 i* l" a
$pager = get_pager('brand.php', $pager['search'], $brand_count, $page, $size);- h# L- c7 C" V U; P* W5 D
$pager['display'] = $display;
% t+ k% z5 D7 H $smarty->assign('pager', $pager);, h9 z, z0 _8 }2 v
$smarty->assign('brand_list', $row);
8 t) A6 U, ]) E4 i% L $smarty->display('brand_list.dwt'); |
3 ?" a& f5 ^# g9 F9 w& [$ f4 R" d1 V7 T. l3 d7 i
2、打开 模板文件 brand_list.dwt2 e- Y; N) g- y
在你想要显示换页信息的地方加入下面代码 j% q1 x7 X: m2 G
<!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem -->
5 j1 x2 I! q4 h' V7 \. S 如果你使用的是官方默认模板,那么在' P, g1 ~, I) G* S7 n
<div class="dashed"></div>4 j6 r8 o% ` R
这行代码下面加$ X8 {: e9 N9 ^* p ~+ H' \ Z
<!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem -->( l9 d/ y* ?! f' r# ?1 R3 I
比较合适。
( H+ p$ t4 e0 `* o |