救命!ECshop 下显示兄弟分类的问题?

2016-07-07 15:06 来源:www.chinab4c.com 作者:ecshop专家

首页标题栏如下分类:

点击男装分类进入到的category.php?id=12 除了他本身的子分类以为,还有兄弟分类的下级分类也都列出来了,我现在想只列出对应男装的子分类,请问大侠如何修改?我研究了一天了,把前面的帖子都找出来看过了,而且对照着修改,都没有成功~各位大哥大姐救我!



回答:
找到lbi_goods.php页面
把调用的那段分类代码修改为:
  1. /**
  2. * 获得指定分类同级的所有分类以及该分类下的子分类
  3. *
  4. * @accesspublic
  5. * @paraminteger$cat_id分类编号
  6. * @returnarray
  7. */
  8. function get_categories_tree($cat_id = 0)
  9. { //当获取到的类别ID大于0的时候
  10. if ($cat_id > 0)
  11. {
  12. //到类别表查询出改类别ID的父ID,并赋值给了$parent_id
  13. $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
  14. $parent_id = $GLOBALS['db']->getOne($sql);
  15. }
  16. else
  17. {
  18. //否则父ID默认为0
  19. $parent_id = 0;
  20. }

  21. /*
  22. 判断当前分类中全是是否是底级分类,
  23. 如果是取出底级分类上级分类,
  24. 如果不是取当前分类及其下的子分类
  25. */
  26. $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$cat_id' AND is_show = 1 ";
  27. $numberC = $GLOBALS['db']->getOne($sql);
  28. if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
  29. {
  30. /* 获取当前分类及其子分类 */
  31. $sql = 'SELECT a.cat_id, a.cat_name, a.sort_order AS parent_order, a.cat_id, a.is_show,' .
  32. 'b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order AS child_order ' .
  33. 'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
  34. 'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id AND b.is_show = 1 ' .
  35. "WHERE a.parent_id = '$parent_id' ORDER BY parent_order ASC, a.cat_id ASC, child_order ASC";
  36. }
  37. else
  38. {
  39. /* 获取当前分类及其父分类 */
  40. $sql = 'SELECT a.cat_id, a.cat_name, b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order, b.is_show ' .
  41. 'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
  42. 'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id AND b.is_show = 1 ' .
  43. "WHERE b.parent_id = '$parent_id' ORDER BY sort_order ASC";
  44. }
  45. $res = $GLOBALS['db']->getAll($sql);

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

  54. if ($row['child_id'] != NULL)
  55. {
  56. if($parent_id > 0 && $numberC > 0 && $row['cat_id'] == $cat_id)
  57. {
  58. $cat_arr[$row['cat_id']]['children'][$row['child_id']]['id']= $row['child_id'];
  59. $cat_arr[$row['cat_id']]['children'][$row['child_id']]['name'] = $row['child_name'];
  60. $cat_arr[$row['cat_id']]['children'][$row['child_id']]['url']= build_uri('category', array('cid' => $row['child_id']), $row['child_name']);
  61. }else if($parent_id == 0 || $numberC == 0 || $numberC == NULL)
  62. {
  63. $cat_arr[$row['cat_id']]['children'][$row['child_id']]['id']= $row['child_id'];
  64. $cat_arr[$row['cat_id']]['children'][$row['child_id']]['name'] = $row['child_name'];
  65. $cat_arr[$row['cat_id']]['children'][$row['child_id']]['url']= build_uri('category', array('cid' => $row['child_id']), $row['child_name']);
  66. }

  67. }
  68. }
  69. }

  70. return $cat_arr;
  71. }
复制代码

我替换过了,可是还是不行~郁闷~下午找了N多方法照着做了就实现不了只显示子目录,总是连兄弟目录都给显示出来了~

2# stanicja

首先感谢一下二楼.
但是不能用..

大哥大姐们,没有会弄这个问题的吗?

我也参照做了,无法实现。我用的是2。6.2的

确实有这样的问题,像我们分类树比较繁多的用户来说,全部显示对我们的顾客造成很大的麻烦,有没有程序高手,帮忙看一下啊.