2.我们增加篇文章和栏目(在哪个后台添加都可以,数据库是一样的):
:
引用标签库:
//栏目查询标签 public function tagColumnlist($tag,$content) { $result= !empty($tag['coulnmulist'])?$tag['coulnmulist']: 'coulnmulist'; $map.=($tag['columnid'])?" {$tag['columnid']} ":"1"; $sql ="db('column')->"; $sql.=($tag['field'])?"field('c_id,c_path,c_name,{$tag['field']}')->":"field('c_id,c_path,c_name')->"; $sql.="where("{$map}")->"; $sql.=($tag['order'])?"order('{$tag['order']}')->":"order('c_order asc')->"; $sql.=($tag['num'])?"limit({$tag['num']})->":""; $sql.="select()->toArray()"; $empty =isset($tag['empty'])?$tag['empty']:''; //下面拼接输出语句 $parsestr = '<?php $_result=htmlOutList('.$sql.',false);'; $parsestr .= 'if($_result)'; $parsestr .= 'foreach($_result as $key=> 这是标签方法,其他的在控制器里面 .$result.'):?>'; $url = "U($column['c_id'])"; $subdata = "db('column')->where('c_parentid',$column['c_id'])->count()"; $parsestr .= '<?php 这是标签方法,其他的在控制器里面 .$result.'["url"]='.$url.'; 这是标签方法,其他的在控制器里面 .$result.'["subdata"]='.$subdata.'; ?>'; $parsestr .= $content;//解析在article标签中的内容 $parsestr .= '<?php endforeach;else?>'; $parsestr .='<?php echo "'.$empty.'";?>'; // dump($parsestr);exit; return $parsestr; } // 内容列表查询 public function tagListarticle($tag,$content){ $result= !empty($tag['result'])?$tag['result']: 'newslist'; $app = 'appindexfacadeCat'; $ids = empty($ids) ? $tag['columnid'] : $tag['columnid'].','.$ids; $column=$tag['columnid']; $map.= $column?" a_columnid in (".$ids.")":"1"; $sql ="db('article')->"; $sql.=($tag['field'])?"field('a_id,a_title,a_pic,a_time,a_columnid,{$tag['field']}')->":"field('a_id,a_title,a_pic,a_time')->"; $sql.="where("{$map}")->"; $sql.=($tag['order'])?"order('{$tag['order']}')->":"order('a_id desc')->"; $sql.=($tag['group'])?"group('{$tag['group']}')->":""; $sql.=($tag['num'])?"limit({$tag['num']})->":""; $sql.="select()->toArray()"; $empty = isset($tag['empty'])?$tag['empty']:''; //下面拼接输出语句 $parsestr = '<?php $_result=htmlOutList('.$sql.',false);'; $parsestr .= 'if($_result)'; $parsestr .= 'foreach($_result as $key=> 这是标签方法,其他的在控制器里面 .$result.'):?>'; $url = "getListUrl($newslist)"; $spic = "getSpic($newslist)"; $parsestr .= '<?php 这是标签方法,其他的在控制器里面 .$result.'["url"]='.$url.'; 这是标签方法,其他的在控制器里面 .$result.'["a_pic"]='.$spic.'; ?>'; $parsestr .= $content;//解析在article标签中的内容 $parsestr .= '<?php endforeach;else?>'; $parsestr .='<?php echo "'.$empty.'";?>'; return $parsestr; }
这是标签方法,其他的在控制器里面