1949啦网--小小 痛苦,是因为能力和欲望不匹配造成的

ECSHOP品牌列表页实现分页

ECSHOP品牌列表页实现分页修改教程

ECSHOP品牌列表页brand.php默认是没有分页的,如果品牌太多了,就不方便了。所以民能加上一个分页功能。

打开brand.php找到

if (empty($brand_id))

{

再找到

exit();

}

将这两者之间的代码全部替换为下面代码

代码如下:

assign_template();

$position = assign_ur_here('', $_LANG['all_brand']);

$smarty->assign('page_title', $position['title']); // 页面标题

$smarty->assign('ur_here', $position['ur_here']); // 当前位置

$smarty->assign('categories', get_categories_tree()); // 分类树

$smarty->assign('helps', get_shop_help()); // 网店帮助

$smarty->assign('top_goods', get_top10()); // 销售排行

$sql = "SELECT count(*) as brand_count from ( select b.brand_id ".

"FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".

$GLOBALS['ecs']->table('goods') . " AS g ".

"WHERE g.brand_id = b.brand_id AND is_show = 1 " .

" AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".

"GROUP BY b.brand_id ) AS gb";

$brand_count=$GLOBALS['db']->getOne($sql); //品牌(含有商品的)数量 

$page = !empty($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;

$size = 3;

$max_page = ($brand_count> 0) ? ceil($brand_count / $size) : 1;

if ($page > $max_page) {$page = $max_page;}

$start=($page - 1) * $size; 

$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 ".

"FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".

$GLOBALS['ecs']->table('goods') . " AS g ".

"WHERE g.brand_id = b.brand_id AND is_show = 1 " .

" AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".

"GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC limit $start,$size";

$row = $GLOBALS['db']->getAll($sql);

foreach ($row AS $key => $val)

{

$row[$key]['url'] = build_uri('brand', array('cid' => $cat, 'bid' => $val['brand_id']), $val['brand_name']);

$row[$key]['brand_desc'] = htmlspecialchars($val['brand_desc'],ENT_QUOTES);

}

$pager['search'] = array( );

$pager = get_pager('brand.php', $pager['search'], $brand_count, $page, $size);

$pager['display'] = $display;

$smarty->assign('pager', $pager);

$smarty->assign('brand_list', $row); 

$smarty->display('brand_list.dwt');

打开 模板文件 brand_list.dwt 在你想要显示换页信息的地方加入下面代码

<!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem -->

如果你使用的是官方默认模板,那么在

<div class="dashed"></div>

这行代码下面添加

<!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem -->

这样就可以在品牌添加分页代码了。

原文链接:https://www.qiquanji.com/post/8309.html

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

微信扫码关注

更新实时通知

作者:xialibing 分类:网页教程 浏览: