1.includes\lib_goods.php, add a few function at the very end
/** * Get sub-categories under the specified category * * @access public * @param integer $cat _id category number * @return array */function get_children_tre E ($cat _id) {if ($cat _id >0) {$sql = ' SELECT count (*) from '. $GLOBALS [' ECS ']->table (' category '). "WHERE parent_id = ' $cat _id '"; if ($GLOBALS [' DB ']->getone ($sql)) {//Gets the current class name and its subclasses $sql = ' SELECT a.cat_id, A.cat_name, A.cat_desc, A.sort_order a S Parent_order, a.cat_id, '. ' b.cat_id as child_id, b.cat_name as Child_name, B.cat_desc as Child_desc, b.sort_order as Child_order '. ' From '. $GLOBALS [' ECS ']->table (' category '). ' As a '. ' Left JOIN '. $GLOBALS [' ECS ']->table (' category '). ' as B on b.parent_id = A.cat_id '. "WHERE a.cat_id = ' $cat _id ' ORDER by a.cat_id asc,parent_order ASC, Child_order ASC";} else{$sql = ' SELECT parent_id from '. $GLOBALS [' ECS ']->table (' category '). "WHERE cat_id = ' $cat _id '"; $parent _id = $GLOBALS [' db ']->getone ($sql); if ($parent _id > 0) {//Get current classification, sibling and parent class $sql = ' SE Lect a.cat_id,A.cat_name, A.cat_desc, b.cat_id as child_id, b.cat_name as Child_name, B.cat_desc as Child_desc, B.sort_order '. ' From '. $GLOBALS [' ECS ']->table (' category '). ' As a '. ' Left JOIN '. $GLOBALS [' ECS ']->table (' category '). ' as B on b.parent_id = A.cat_id '. "WHERE b.parent_id = ' $parent _id ' ORDER by Sort_order ASC";} else{//gets the current classification $sql = ' SELECT a.cat_id, A.cat_name from '. $GLOBALS [' ECS ']->table (' category '). ' As a '. "WHERE a.cat_id = ' $cat _id '"; }} $res = $GLOBALS [' db ']->getall ($sql); $cat _arr = Array (); foreach ($res as $row) {$cat _arr[$row [' cat_id ']][' id '] = $row [' cat_id ']; $cat _arr[$row [' cat_id ']][' name '] = $row [' Cat_ Name ']; $cat _arr[$row [' cat_id ']][' url '] = Build_uri (' category ', Array (' cid ' = $row [' cat_id ']), $row [' cat_name ']); $cat _arr[$row [' cat_id ']][' cat_desc '] = $row [' Cat_desc '];if ($row [' child_id ']! = NULL) {$cat _arr[$row [' cat_id ']][' Children '] [$row [' child_id ']][' id '] = $row [' child_id ']; $cat _arr[$row [' cat_id ']][' chiLdren '] [$row [' child_id ']][' name '] = $row [' Child_name ']; $cat _arr[$row [' cat_id ']][' children '] [$row [' child_id ']][' URL '] = Build_uri (' category ', Array (' cid ' = $row [' child_id ']), $row [' Child_name ']), $cat _arr[$row [' cat_id ']][' Children '] [$row [' child_id ']][' cat_desc '] = $row [' Child_desc '];}} return $cat _arr; }}/** * Gets the specified category product * * @access public * @param string $cat _id (num) _best_goods * @param array $ca t_id (num) _best_goods * @return array */function get_cat_id_goods_list ($cat _id = ', $num = ') {$sql = ' Select g.good s_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, G.sales_volume_base, G.is_shipping, '. "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)))). $sql. = "ORDER by g.sales_volume_base DESC LIMIT $num"; $res = $GLOBALS [' db ']->getall ($sql); $goods = Array (); foreach ($r Es as $idx = + $row) {$goods [$idx] [' id '] = $row [' goods_id ']; $goods [$IDX] [' name '] = $row [' Goods_name ']; $goods [$IDX] [' Brief '] = $row [' Goods_brief ']; $goods [$idx] [' sales_volume_base '] = $row [' sales_volume_base ']; $goods [$idx] [' Is_ Shipping '] = $row [' is_shipping ']; $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] [' promote_price '] = Price_format ($ row[' Promote_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;} /** * Get albums for a specified category of products * * @access public * @param string $cat _idnum_best_goods * @param array $cat _idnum_best_goods * @return Array */function get_thumb ($goods _id) {$sql = "select Img_url,thumb_url from". $GLOBALS [' ECS ']->table (' Goods_gallery '). " WHERE goods_id = ". $goods _id; $res = $GLOBALS [' db ']->getall ($sql); return $res;}
2.category.php, in
$smarty->assign (' Feed_url ', ($_cfg[' rewrite ') = = 1)? "Feed-c$cat_id.xml": ' feed.php?cat= '. $cat _id); RSS URL
Later, add
/******************************************************************************************* */ //The confidence in the classification page to invoke the current classification and its level two classification, and then to downgrade each category by 5 items $cats = Get_children_tree ($cat _id);// Get current classification information and sub-classification information $cat _detail = Array (); foreach ($cats as $key + $val) { foreach ($cats [$key] [' children '] as $_k =>$_v) { $cats [$key] [' Children '][$_k][' goods_detail '] = get_cat_id_goods_list ($ _v[' id '],5); foreach ($cats [$key] [' Children '][$_k][' Goods_ Detail '] as $_ke =>$_va) { $cats [$key] [' Children '][$_k][' goods_detail '][$_ke][' thumb_url '] = Get_thumb ($_va[' id '); } } $cat _detail = $cats [$key] [' Children '];//Current classification of class two and its product information } $smarty Assign (' Cat_detail ', $cat _detail); /**************************** ****************************************************************/
<!--cycle Class two--><!--{foreach from= $cat _detail item=cat name=cats_detail}--><div id=content class= "W pt10 "> <div class=" Lzo "> <div class=" lzt ">
:
Ok! Complete, incidentally, this cycle classification and display classification under the function of the product before Bo Master I found on the internet for a long time did not find, hence, simply self-developed. The most critical is the category.php inside of the Foreach loop, interested students can study to see. I hereby share it with my friend.
To reprint please specify the Source: http://blog.csdn.net/glatchen/article/details/42238499
Ecshop Product List page, cycle through the current classification of level two categories and products under classification