今天在群上看到subcat函數,用來調用子欄目,之前發過一篇利用嵌套遍歷出子欄目的方法,發現這函數更加方便,看代碼:
- * 獲取子欄目
- * @param $parentid 父級id
- * @param $type 欄目類型
- * @param $self 是否包含本身 0為不包含
- * @param $siteid 站點id
- function subcat($parentid = NULL, $type = NULL,$self = '0', $siteid = '') {
- if (emptyempty($siteid)) $siteid = get_siteid();
- $category = getcache('category_content_'.$siteid,'commons');
- foreach($category as $id=>$cat) {
- if($cat['siteid'] == $siteid && ($parentid === NULL || $cat['parentid'] == $parentid) && ($type === NULL || $cat['type'] == $type)) $subcat[$id] = $cat;
- if($self == 1 && $cat['catid'] == $parentid && !$cat['child']) $subcat[$id] = $cat; //Vevb.com
- }
- return $subcat;
- }
此函數返回的array里面就是$catid的所有子欄目,所以調用方法為如下代碼:
{loop subcat($catid) $v}.
非常簡單.
新聞熱點
疑難解答