/** * 配置管理 * @author 枫叶 <*****@*****.**> */ public function index() { //分类 $field = get_model_attr('article', 'category_id'); $field['title'] = '分类'; $field['attrtype'] = 0; $field['value'] = I('category_id', '0'); //附加属性 $field1 = get_model_attr('article', 'position'); $field1['type'] = 'select'; $field1['title'] = '位置'; $field1['extra'][0] = '全部'; $field1['attrtype'] = 0; $field1['value'] = I('position', '0'); $field = [$field, $field1]; $field[] = ['field' => 'title', 'type' => 'text', 'name' => 'title', 'title' => '标题', 'note' => '', 'value' => I('title', ''), 'is_show' => 3]; $this->assign('fieldarr', $field); $this->assign('data', null); /* 查询条件初始化 */ $map = array(); $map['status'] = 1; $map['category_type'] = 'article'; $title = I('title'); $category_id = I('category_id'); $position = I('position'); if ($position !== '0' && $position !== '') { $map['position'] = array('like', '%' . $position . '%'); } if (!empty($title)) { $map['title'] = array('like', '%' . $title . '%'); } if (!empty($category_id)) { $allid = get_category_allchild($category_id); $map['category_id'] = array('in', "{$allid}"); } $field = 'article_id,title,pic,position,category_id,status,update_time,create_time'; $list = $this->pages(array('field' => $field, 'order' => 'article_id desc', 'model' => 'article', 'where' => $map)); $this->meta_title = '文章列表'; $this->display(); }
/** * 取指定分类文章 */ function get_category_article($category_id = '', $rows = '8') { if (empty($category_id)) { return ''; } $rearr = array(); $category_id = get_category_allchild($category_id); $map['category_id'] = array('in', "{$category_id}"); $map['status'] = 1; $skey = 'homearticlelist' . $category_id; $rearr = S($skey); if (empty($rearr) || APP_DEBUG) { $rearr = M('Article')->where($map)->order('article_id desc')->limit($rows)->select(); S($skey, $rearr); } return $rearr; }
/** *取当前分类的所有子类树 */ function get_category_allchild($id) { $restr = F('cateallchild' . $id); if (empty($restr) || APP_DEBUG) { $restr = $id; $map['pid'] = $id; $result = M('Category')->where($map)->select(); if (!empty($result)) { foreach ($result as $key => $val) { $temid = $val['category_id']; $result1 = M('Category')->where("pid=" . $temid)->select(); if (!empty($result1)) { $temid = get_category_allchild($temid); } $restr .= ',' . $temid; } } F('cateallchild' . $id, $restr); } return $restr . ''; }