联系我们

18176930112


建站、模板咨询

destoon商铺模板调用系统分类

sell/list.html 调用sell的系统分类

{loop $maincat $k $v}

输出分类
{/loop}
$maincat

列表页面系统分类 $maincat = get_maincat($child ? $catid : $parentid, $moduleid); // $child : $moduleid -模型id 列表页面可以显示当前父类的子类。

首页系统分类 $maincat = get_maincat($catid ? $CAT[‘parentid‘] : 0, $moduleid); 首页应该显示全部分类

get_maincat 函数 在global.func.php 定义

// $catid-父类 ,>0时读取其子类,否则读取$moduleid模型的所有顶级类别

function get_maincat($catid, $moduleid, $level = -1) {
global $db;
$condition = $catid ? "parentid=$catid" : "moduleid=$moduleid AND parentid=0";
if($level >= 0) $condition .= " AND level=$level";
$cat = array();
$result = $db->query("SELECt catid,catname,child,style,linkurl,item FROM {$db->pre}category WHERe $condition ORDER BY listorder,catid ASC", ‘CACHE‘);
while($r = $db->fetch_array($result)) {
$cat[] = $r;
}
return $cat;
}

(1) 在init.inc.php 中include DT_ROOT.‘/module/company/‘.$file.‘.inc.php‘; 之前添加函数

//分类arr1 是否在分类数组$arr2中出现过 出现过就返回true 为什么直接in_array 不行 难道是数组是通过fetch_array生成的原因,带着字段名
function issubs($arr1,$arr2){
foreach ($arr1 as $a){
foreach($arr2 as $b){
if($a[‘catid‘]==$b[‘catid‘]) return ture;
}
}
return false;
}

(2)店铺模板的side_type.htm 中

开头的php中增加

<?php
isset($typeid) or $typeid = 0;
$_file = $file;
if($file == ‘mall‘) {
$_item = ‘mall-‘.$userid;
$_name = ‘商品分类‘;
//} else if($file == ‘news‘) {
// $_item = ‘news-‘.$userid;
// $_name = ‘新闻分类‘;
} else {
$_item = ‘product-‘.$userid;
$_name = ‘产品分类‘;
$_file = ‘sell‘;
}
$_TYPE = get_type($_item);
$_TP = $_TYPE ? sort_type($_TYPE) : array();

//以上是读取自定义分类的 基本上用不到

if($file==‘xianhuo‘){
//读取现货分类
$maincatModule=23;
$_file = ‘xianhuo‘;
}else{
//读取产品分类
$maincatModule=5;
$_file = ‘sell‘;
}

//读取当前用户有产品的分类
$sql="select catid from {$db->pre}sell_".$maincatModule." where username=".$username." group by catid ";
$query=$db->query($sql);
while($r = $db->fetch_array($query)) {
$cat[] = $r; //$cat用于筛选有产品分类的父类(一级分类)
$cat_catid[]=$r[‘catid‘]; //$cat_catid 用于筛选有产品分类(二级分类)

}

$maincat = get_maincat(0,$maincatModule); //读取$maincatModule指定模型的一级分类。

?>

循环输出 一级分类和二级分类:

{loop $maincat $v0}
{php $sub=get_maincat($v0[catid],$maincatModule,1);} <!--读取本循环的二级分类-->
{if issubs($cat,$sub)} //issub函数在init.inc.php里定义 当前一级类别的子类里有用户添加的产品的分类

<li id="type_{$v0[catid]}"{if $typeid==$v0[catid]} class="f_b"{/if}><a class="com-1" href="{userurl($username, ‘file=‘.$_file.‘&catid=‘.$v0[‘catid‘], $domain)}" title="{$v0[catname]}"><i class="icon-double-angle-right com-1-i"></i><span class="com-1-txt">{$v0[catname]}</span></a></li>
{loop $sub $v1}
{if in_array($v1[catid],$catcatid)} //当前二级分类里有用户添加产品的分类
<li id="type
{$v1[catid]}"{if $catid==$v1[catid]} class="f_b"{/if}><a class="com-2" href="{userurl($username, ‘file=‘.$_file.‘&catid=‘.$v1[‘catid‘], $domain)}" title="{$v1[catname]}">{$v1[catname]}</a></li>
{/if}
{/loop}
{/if}
{/loop}

导航和产品页面也有产品二级菜单所以把 这些代码放到init.inc.php里 在需要的地方直接像上边一样循环调用即可,注意 {loop $sub $v1} 中的$v1 会跟详情页面的v1 v2 v3中的$v1 冲突 要是$v1换成别的,loop标签里的变量可能跟页面其他同名变量冲突。

//分类arr1 是否在分类数组$arr2中出现过 出现过就返回true 为什么直接in_array 不行 难道是数组是通过fetch_array生成的原因,带着字段名

function issubs($arr1,$arr2){

foreach ($arr1 as $a){

foreach($arr2 as $b){if($a[‘catid‘]==$b[‘catid‘]) return ture;}

}

return false;

}

if($file==‘xianhuo‘){

//读取现货分类

$maincatModule=23;

$_file = ‘xianhuo‘;

}else{

//读取产品分类

$maincatModule=5;

$_file = ‘sell‘;

}

//读取当前用户有产品或现货的分类,用于只显示有产品的分类

$sql="select catid from {$db->pre}sell_".$maincatModule." where username=".$username." group by catid ";

$query=$db->query($sql);

while($r = $db->fetch_array($query)) {

$cat[] = $r;

$cat_catid[]=$r[‘catid‘];

}

$maincat = get_maincat(0,$maincatModule); //现货的时候显示现货分类,其他时候显示产品分类


电话

咨询电话:
4008857862
18176930112 13878897862

微信咨询

千人QQ交流群

购物车

客服

顶部