📄 正在查看:twcms/block/kp_block_category.lib.php
大小:1,385 字节 · 修改:2014-01-23 01:42:52 · 行数:49
1<?php
2defined('KONG_PATH') || exit;
3
4/**
5 * 分类展示模块
6 * @param int cid 分类ID 如果不填:自动识别
7 * @param string type 显示类型 同级(sibling)、子级(child)、父级(parent)、顶级(top)
8 * @param int mid 模型ID (默认自动识别)
9 * @return array
10 */
11function kp_block_category($conf) {
12 global $run;
13
14 // hook kp_block_category_before.php
15
16 $cid = isset($conf['cid']) ? intval($conf['cid']) : _int($_GET, 'cid');
17 $mid = isset($conf['mid']) ? intval($conf['mid']) : (isset($run->_var['mid']) ? $run->_var['mid'] : 2);
18 $type = isset($conf['type']) && in_array($conf['type'], array('sibling', 'child', 'parent', 'top')) ? $conf['type'] : 'sibling';
19
20 $cate_arr = $run->category->get_category_db();
21
22 switch($type) {
23 case 'sibling':
24 $upid = isset($cate_arr[$cid]) ? $cate_arr[$cid]['upid'] : 0;
25 break;
26 case 'child':
27 $upid = $cid;
28 break;
29 case 'parent':
30 $upid = isset($cate_arr[$cid]) ? $cate_arr[$cid]['upid'] : 0;
31 $upid = isset($cate_arr[$upid]) ? $cate_arr[$upid]['upid'] : $upid;
32 break;
33 case 'top':
34 $upid = 0;
35 }
36
37 foreach($cate_arr as $k => &$v) {
38 if($v['upid'] != $upid || $v['mid'] != $mid) {
39 unset($cate_arr[$k]);
40 }else{
41 $v['url'] = $run->category->category_url($v['cid'], $v['alias']);
42 }
43 }
44
45 // hook kp_block_category_after.php
46
47 return $cate_arr;
48}
49