当前位置:首页 > 教程中心 > CMS教程 > EcShop

ecshop 首页调用全部分类树 并且分类下的品牌 &调用商品分类指定分类下级分类

所属栏目:EcShop 时间:2014-03-21 来源:网络 作者:不详 点击:

index.dwt里代码:

<!--{foreach from=get_categories_tree(0) item=cat name=cat0}-->
               <div id="JS_hide_side_menu_{$smarty.foreach.cat0.iteration}" class="item all" onmouseover="showMenu(this,'side','{$smarty.foreach.cat0.iteration }')" onmouseout="hideMenu(this,'side','{$smarty.foreach.cat0.iteration}')">
                 <div class="hideMenu {if $smarty.foreach.cat0.iteration >3}to{$smarty.foreach.cat0.iteration}{/if}">
                   <div class="menuList">
                       <div>
<h4>热门品牌</h4>
                       <p>
                       <!--{foreach from=get_brands1($GLOBALS['smarty']->_var['cat']['id']) item=bchilder name=name1}-->
                       {if $smarty.foreach.name1.iteration < 4} <a  href="{$bchilder.url}" target="_blank" title=""><img src="data/brandlogo/{$bchilder.brand_logo}"  width="91" height="35" alt="" /></a> {/if}
                       <!--{/foreach}-->
                       </p>
                    </div>
                     <!--{foreach from=$cat.cat_id item=child name=name}-->
                     <!--{if $smarty.foreach.name.iteration lt 7}-->
                     <div class="list {if $smarty.foreach.name.first}first{/if} clearfix">
                       <h4>{$child.name|escape:html}</h4>
                       <p><!--{foreach from=$child.cat_id item=childer}-->
                         <a href="{$childer.url}" target="_blank" title="{$childer.name|escape:html}">&nbsp;{$childer.name|escape:html}&nbsp;</a>|<!--{/foreach}--></p>
                     </div>
                     <!--{/if}-->
                     <!--{/foreach}-->
                   </div>
                 </div>
                 <dl>
                   <dt> <a href="{$cat.url}" target="_blank" title="{$cat.name|escape:html}">{$cat.name|escape:html}</a> </dt>
                 </dl>
               </div>
               <!--{/foreach}-->

index.php代码

//得到分类下的品牌
function get_brands1($url = 0, $app = 'brand')
{
    preg_match("/\d+/i",$url,$matches);
    $cat = $matches[0];
    $children = ($cat > 0) ? ' AND ' . get_children($cat) : '';
    $sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, b.brand_desc, COUNT(*) AS goods_num, IF(b.brand_logo > '', '1', '0') AS tag ".
            "FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".
                $GLOBALS['ecs']->table('goods') . " AS g ".
            "WHERE g.brand_id = b.brand_id $children AND is_show = 1 " .
            " AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
            "GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC";
    $row = $GLOBALS['db']->getAll($sql);
    foreach ($row AS $key => $val)
    {
        $row[$key]['url'] = build_uri($app, array('cid' => $cat, 'bid' => $val['brand_id']), $val['brand_name']);
        $row[$key]['brand_desc'] = htmlspecialchars($val['brand_desc'],ENT_QUOTES);
    }
    return $row;
}
//*** 调用商品分类指定分类下级分类
function get_parent_id_tree($parent_id)
{
    $three_c_arr = array();
    $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
    if ($GLOBALS['db']->getOne($sql))
    {
        $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
                'FROM ' . $GLOBALS['ecs']->table('category') .
                "WHERE parent_id = '$parent_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_c_arr[$row['cat_id']]['id']   = $row['cat_id'];
               $three_c_arr[$row['cat_id']]['name'] = $row['cat_name'];
               $three_c_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
        }
    }
    return $three_c_arr;
}


请站长喝杯咖啡?

站长一直坚持白天工作、晚上熬夜更新素材,付出了巨大的精力和时间,其中的辛酸难以言述。

坚持免积分、免登录、无任何限制下载!如果本站素材对你有用,不妨考虑请站长喝杯咖啡鼓励一下!

标签:品牌

你应该也喜欢这些吧

共有 1 条评论

给个评价吧

验证码: