百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>destoon教程> destoon商铺模板调取系统分类
分享文章到:

destoon商铺模板调取系统分类

发布时间:08/25 来源:未知 浏览: 关键词:

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用于挑选有产品分类的父类(1级分类)
$cat_catid[]=$r[‘catid‘]; //$cat_catid 用于挑选有产品分类(二级分类)

}

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

?>

轮回输出 1级分类和二级分类:

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

<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); //现货的时候显示现货分类,其他时候显示产品分类


打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有150人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板