ecshop导航分类调用二级分类

2012-02-11 23:01 来源:www.chinab4c.com 作者:ecshop专家

    ecshop导航分类调用二级分类甚至是三级分类。这样就可以通过导航上的分类id进行下拉。这样的话,只要是ecshop导航调用商品分类,我们都可以将他下面的分类以下拉的形式展现,这样的让ecshop很多功能显现的更加完美。

    1:includes/lib_main.php增加以下函数,用来调用指定分类下的子分类的。

    function get_top_child_tree($tree_id = 0)
{
    $three_arr = array();
    $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";
    if ($GLOBALS['db']->getOne($sql) || $tree_id == 0)
    {
        $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
                'FROM ' . $GLOBALS['ecs']->table('category') .
                "WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
        $res = $GLOBALS['db']->getAll($child_sql);
        foreach ($res AS $row)
        {
            if ($row['is_show'])

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

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

            }
        }
    }
    return $three_arr;
}

   2:我们要在function get_navigator($ctype = '', $catlist = array())函数里面,增加以下代码,来将导航中商品分类的id取得,从而取得他下面的商品分类。

    if($v['ctype']=='c'){
   
     $navlist['middle'][$k]['list'] =get_top_child_tree($v['cid']) ;

  }

   3:最后我们在ecshop的模板库文件中,通过以下方式调用导航下拉分类。 

    {if $nav.list1}
     {foreach from = $nav.list1 item = child1}
     <div class="listbox">
              <p>{$child1.name}</p>
       {if $child1.cat_id}
              <ul>
          {foreach from=$child1.cat_id item =child2}
                <li><a href="{$child2.url}" title="{$child2.name}">{$child2.name}</a></li>
  {/foreach}
              </ul>
       {/if}
            </div>
     {/foreach}
           {/if}
 

来源:http://www.chinab4c.com