默认的phpcms 的tag是无法筛选catid的,如需要按catid进行筛选首选我们需要将catid写入数据表中,方法参照phpcms 关键词keyword表加入栏目catid的方法
然后修改phpcms/,odules/content/tag.php 找到public function lists()进行修改,请参照如下代码
public function lists() { //传入siteid参数 --wjb if(isset($_GET['siteid'])) { $siteid = intval($_GET['siteid']); } else { $siteid = 1; } $tag = safe_replace(addslashes($_GET['tag'])); $keyword_data_db = pc_base::load_model('keyword_data_model'); //获取标签id $r = $this->keyword_db->get_one(array('keyword'=>$tag, 'siteid'=>$this->siteid), 'id'); if (!$r['id']) showmessage('不存在此关键字!'); //$tagid = intval($r['id']); $tagid = intval($_GET['id']); $catid = intval($_GET['catid']);//获取catid if (!$tagid) { //tagid为空读取数据库 $h = $this->keyword_db->get_one(array('keyword'=>$tag, 'siteid'=>$siteid, 'catid'=>$catid)); $tagid = $h['id']; } $page = max($_GET['page'], 1); $pagesize = 20; $where = '`tagid`=\''.$tagid.'\' AND `siteid`='.$this->siteid; $infos = $keyword_data_db->listinfo($where, '`id` DESC', $page, $pagesize); $pages = $keyword_data_db->pages; $total = $keyword_data_db->number; if (is_array($infos)) { $datas = array(); foreach ($infos as $info) { list($contentid, $modelid) = explode('-', $info['contentid']); $this->db->set_model($modelid); $res = $this->db->get_one(array('id'=>$contentid), 'title, thumb, description, url, inputtime, style'); //加入缩略图调用 //$res['title'] = str_replace($tag, '<font color="#f00">'.$tag.'</font>', $res['title']); $res['title'] = str_replace($tag, ''.$tag.'', $res['title']); //$res['description'] = str_replace($tag, '<font color="#f00">'.$tag.'</font>', $res['description']); $res['description'] = str_replace($tag, ''.$tag.'', $res['description']); $datas[] = $res; } } $SEO = seo($siteid, '', $tag); include template('content','tag_list'); }
前端调用方法
{pc:get sql="SELECT id,keyword FROM `v9_keyword` WHERE siteid=$siteid AND catid=27 ORDER BY `videonum` DESC" num="66"} // {loop $data $r} {php $num++} <a href="{APP_PATH}index.php?m=content&c=tag&catid=27&a=lists&id={$r[id]}&tag={urlencode($r['keyword'])}" title="{$r[keyword]}">{$r[keyword]}</a> {/loop} {/pc}
- 前一篇: 在PHPCMS中修改会员头像上传尺寸
- 后一篇: 神呐,让PHPCMSX的TAG有伪静态吧