求显示指定分类下的子分类方法

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

我想获取指定分类下的子分类,请问这个可以实现吗,哪位高手可以指点一下

回答:
期待高手指点

高手指点 啊

貌似这方法实用,我去试下,谢谢楼上的

{$cat.name|escape:html}

把上面代码复制到你的模板中就可以实现,其中上面三个“256”要改成你指定的分类id。

简单的就是这样,要正式应用还得结合实际对模板美化一下
鸿豪科技 发表于 2009-8-27 07:31


Fatal error: Call to a member function assign() on a non-object in D:\php\Htdocs\coollipin\includes\cls_template.php(1161) : eval()'d code on line 24

错误提示,测试了不行

不好意思,代码写错了
  1. <?php $this->assign('categories256', get_categories_tree(256));?>

  2. <!--{foreach from=$categories256 item=cat}-->

  3. <A href="{$cat.url}">{$cat.name|escape:html}</A><br/>

  4. <!--{/foreach}-->
复制代码

2.7后 系统有这个函数
  1. function get_child_tree($tree_id = 0)
  2. {
  3. $three_arr = array();
  4. $sql = 'SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";
  5. $cat_name = $GLOBALS['db']->getOne($sql);

  6. $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";

  7. if ($GLOBALS['db']->getOne($sql) || $tree_id == 0)
  8. {
  9. $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
  10. 'FROM ' . $GLOBALS['ecs']->table('category') .
  11. "WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
  12. $res = $GLOBALS['db']->getAll($child_sql);
  13. foreach ($res AS $row)
  14. {
  15. if ($row['is_show'])

  16. $three_arr[$row['cat_id']]['id']= $row['cat_id'];
  17. $three_arr[$row['cat_id']]['name'] = $row['cat_name'];
  18. $three_arr[$row['cat_id']]['url']= build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);

  19. if (isset($row['cat_id']) != NULL)
  20. {
  21. $three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);

  22. }
  23. }
  24. }
  25. else
  26. {
  27. $sql = 'SELECT parent_id,cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$tree_id' AND is_show = 1 ";
  28. $rows = $GLOBALS['db']->getRow($sql);
  29. $parent_id = $rows['parent_id'];
  30. $cat_name = $rows['cat_name'];
  31. $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
  32. 'FROM ' . $GLOBALS['ecs']->table('category') .
  33. "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
  34. $res = $GLOBALS['db']->getAll($child_sql);
  35. foreach ($res AS $row)
  36. {
  37. if ($row['is_show'])

  38. $three_arr[$row['cat_id']]['id']= $row['cat_id'];
  39. $three_arr[$row['cat_id']]['name'] = $row['cat_name'];
  40. $three_arr[$row['cat_id']]['url']= build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
  41. }
  42. }
  43. $arr['cat_list'] = $three_arr;
  44. $arr['cat_name'] = $cat_name;
  45. return $arr;
  46. }
复制代码

同求此功能,2.7的那个函数,怎么在模板里调用呢?希望可以具体指教一下在模板里如何调用

2.72 原版不是这样我改成你的 结果输出乱码

这个得顶上去太需要这个功能了

还有就是指定分类下的所有商品显示