The ecshop product list page displays the second-level categories of the current category and the products under the category. The ecshop product list
1. includes \ lib_goods.php, add several functions at the end
/*** Obtain the subcategory of the specified category ** @ access public * @ param integer $ cat_id Category Number * @ return array */function get_children_tree ($ cat_id) {if ($ cat_id> 0) {$ SQL = 'select count (*) from '. $ GLOBALS ['ecs']-> table ('category '). "WHERE parent_id = '$ cat_id'"; if ($ GLOBALS ['db']-> getOne ($ SQL )) {// obtain the current category name and its subclass $ SQL = 'select. cat_id,. cat_name,. cat_desc,. sort_order AS parent_order,. 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 '. 'Left join '. $ GLOBALS ['ecs']-> table ('category '). AS B ON B. parent_id =. cat_id '. "WHERE. cat_id = '$ cat_id' order by. 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) {// obtain the current category, sibling and its parent class $ SQL = 'select. cat_id,. cat_name,. 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 '. 'Left join '. $ GLOBALS ['ecs']-> table ('category '). AS B ON B. parent_id =. cat_id '. "WHERE B. Parent_id = '$ parent_id 'order BY sort_order ASC ";} else {// get the current category $ SQL = 'select. cat_id,. cat_name FROM '. $ GLOBALS ['ecs']-> table ('category '). AS '. "WHERE. 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;}/*** get the product of the specified category ** @ access public * @ param string $ cat_id (num) _ best_goods * @ param array $ cat_id (num) _ best_goods * @ return array */function get_cat_id_goods_list ($ 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, 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 ($ res 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 ;} /*** obtain the album of a specified category ** @ 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
Add
/*************************************** **************************************** * ************ // Call the current category and the confidence of its secondary category on the category page, call five products under each category $ cats = get_children_tree ($ cat_id); // obtain the information of the current category and Its subcategory $ 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 ']; // second-level category and item information under the current category} $ smarty-> assign ('cat _ detail ', $ cat_detail ); /*************************************** **************************************** *************/
<! -- Cyclic second-level classification --> <! -- {Foreach from = $ cat_detail item = cat name = cats_detail} --> <div id = content class = "w pt10"> <div class = "lzo"> <div class = "lzt">
:
OK! Complete. Let's just talk about it. I haven't found the function of this cyclic category and the product under the category for a long time before I found it on the Internet. I just want to develop it myself. The most important thing is the foreach loop in category. php. If you are interested, you can study it. I would like to share with you.
If you want to reprint please indicate the source: http://blog.csdn.net/glatchen/article/details/42238499