ECShop2.72只显示当前分类与其子分类的代码

2016-07-07 14:56 来源:www.chinab4c.com 作者:ecshop专家

我的网站打开分类时会很长,就是左侧的分类打开某一类类目或者商品时,我只想让他显示当前分类及其子分类,我拿2.71的方法放在我那上面不好用,哪位大哥知道方法教小弟一下谢谢了

回答:
这个问题我也在烦。。。希望有答案的人提供下

找不到,很需要这个呀

等待解决

这个我最近刚刚在改,百度有,不过不好找

修改PHP代码的吧,不懂PHP还是不要改算了。

修改function get_categories_tree函数
中文乱码了,讲究着看吧

  1. function get_categories_tree($cat_id = 0)
  2. {
  3. if ($cat_id > 0)
  4. {
  5. $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
  6. $parent_id = $GLOBALS['db']->getOne($sql);
  7. }
  8. else
  9. {
  10. $parent_id = 0;
  11. }

  12. /*
  13. 鍒ゆ柇褰撳墠鍒嗙被涓?叏鏄?槸鍚︽槸搴曠骇鍒嗙被锛?
  14. 濡傛灉鏄?彇鍑哄簳绾у垎绫讳笂绾у垎绫伙紝
  15. 濡傛灉涓嶆槸鍙栧綋鍓嶅垎绫诲強鍏朵笅鐨勫瓙鍒嗙被
  16. */
  17. $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$cat_id' AND is_show = 1 ";
  18. if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
  19. {
  20. /* 鑾峰彇褰撳墠鍒嗙被鍙婂叾瀛愬垎绫?*/
  21. $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
  22. 'FROM ' . $GLOBALS['ecs']->table('category') .
  23. "WHERE parent_id = '$cat_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

  24. $res = $GLOBALS['db']->getAll($sql);

  25. foreach ($res AS $row)
  26. {
  27. if ($row['is_show'])
  28. {
  29. $cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
  30. $cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
  31. $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);

  32. if (isset($row['cat_id']) != NULL)
  33. {
  34. $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
  35. }
  36. }
  37. }
  38. }

  39. else
  40. {


  41. /* 鑾峰彇褰撳墠鍒嗙被鍙婂叾瀛愬垎绫?*/
  42. $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
  43. 'FROM ' . $GLOBALS['ecs']->table('category') .
  44. "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

  45. $res = $GLOBALS['db']->getAll($sql);

  46. foreach ($res AS $row)
  47. {
  48. if ($row['is_show'])
  49. {
  50. $cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
  51. $cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
  52. $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);

  53. if (isset($row['cat_id']) != NULL)
  54. {
  55. $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
  56. }
  57. }
  58. }
  59. }
  60. if(isset($cat_arr))
  61. {
  62. return $cat_arr;
  63. }
  64. }
复制代码