本文是361源碼今天早上起床后看到的一篇文章,感覺有參考價值,就轉載過來了,如有版權,請聯系本站處理。
用PHPCMS創建了PC站的tags匯總頁和列表頁,通過統計觀察效果還不錯,有不少人訪問,因此想在移動端手機站上也創建tags匯總頁和列表頁,可是默認只能在 /phpcms/templates/default/content 創建一個tag.html和tag_list.html頁面,在PC端用了移動端就用不了了,361源碼網站長思考了下,能不能在移動端 /phpcms/templates/default/wap 目錄下也創建一個tag.html和tag_list.html 頁面來實現呢?下面就是武林網站長的實現方法,希望對有需要的朋友有所幫助。
1、將 /phpcms/modules/content/tag.php 文件拷貝到 /phpcms/modules/wap 目錄下
2、打 /phpcms/modules/wap/tag.php 文件
2.1、將 pc_base::load_app_func('util','content'); 注釋或刪除,并在原位置添加 pc_base::load_app_func('global');
2.2、將 __construct() 函數中 $this->siteid = get_siteid(); 注釋或刪除,并在原位置下邊添加
$this->siteid = isset($_GET['siteid']) && (intval($_GET['siteid']) > 0) ? intval(trim($_GET['siteid'])) : (param::get_cookie('siteid') ? param::get_cookie('siteid') : 1);param::set_cookie('siteid',$this->siteid); $this->wap_site = getcache('wap_site','wap');$this->types = getcache('wap_type','wap');$this->wap = $this->wap_site[$this->siteid];define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid);if($this->wap['status']!=1) exit(L('wap_close_status'));
2.3、將 include template('content', 'tag'); 修改為 include template('wap', 'tag');
2.4、找到 $res = $this->db->get_one(array('id'=>$contentid), 'title, description, url, inputtime, style');
修改為
$res = $this->db->get_one(array('id'=>$contentid), 'catid, title, description, inputtime, style');
此步驟添加 catid, 并刪除 url,
2.5、找到 $res['description'] = str_replace($tag, '<font color="#f00">'.$tag.'</font>', $res['description']); 并在此代碼下邊添加
$catid = $res['catid'];$types = getcache('wap_type','wap');foreach ($types as $type) { if($type['cat']==$catid) { $typeid = $type['typeid']; break; }}$res['url'] = WAP_SITEURL."&a=show&catid=".$catid."&typeid=".$typeid."&id=".$contentid;
2.6、將 include template('content','tag_list'); 修改為 include template('wap','tag_list');
2.7、如想看完整文件請在文章最下邊看
3、文章內容頁調用示例:
{loop $keywords $keyword}<a title="www.49028c.com" href="{WAP_SITEURL}m=wap&c=tag&a=lists&tag={urlencode($keyword)}">{$keyword}</a>{/loop}
4、在 /phpcms/templates/default/wap 目錄下創建 tag.html 即為tags匯總頁 tag_list.html 即為tags列表頁
5、tag.html調用標簽示例:
{loop $infos $info} <p><a title="www.49028c.com" href="{WAP_SITEURL}m=wap&c=tag&a=lists&tag={urlencode($info['keyword'])}">{$info['keyword']}</a>({$info['videonum']})</p>{/loop}
6、tag_list.html調用標簽示例:
<div> <ul>{loop $datas $r} <li><span class="www.49028c.com">{date('Y-m-d H:i:s',$r[inputtime])}</span>·<a href="{$r[url]}" title="www.49028c.com" target="_blank">{$r[title]}</a></li>{/loop} </ul> <div id="pages">{$pages}</div></div>
7、/phpcms/modules/wap/tag.php 文件完整展示
<?php/* * * PHPCMS V9二次開發之wap手機站創建tags匯總頁(tag.html)列表頁(tag_list.html) * 此文章由武林網(www.49028c.com)創作,轉載請注明版權 * */defined('IN_PHPCMS') or exit('No permission resources.');//模型緩存路徑define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);//此處將 pc_base::load_app_func('util','content'); 刪除,并在原位置添加 pc_base::load_app_func('global');pc_base::load_app_func('global');class tag { private $db; function __construct() { $this->db = pc_base::load_model('content_model'); $this->keyword_db = pc_base::load_model('keyword_model'); //此處將 $this->siteid = get_siteid(); 刪除并添加如下代碼,直到此函數最后 $this->siteid = isset($_GET['siteid']) && (intval($_GET['siteid']) > 0) ? intval(trim($_GET['siteid'])) : (param::get_cookie('siteid') ? param::get_cookie('siteid') : 1); param::set_cookie('siteid',$this->siteid); $this->wap_site = getcache('wap_site','wap'); $this->types = getcache('wap_type','wap'); $this->wap = $this->wap_site[$this->siteid]; define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid); if($this->wap['status']!=1) exit(L('wap_close_status')); } public function init() { $page = max($_GET['page'], 1); $pagesize = 20; $where = '`siteid`='.$this->siteid; $infos = $this->keyword_db->listinfo($where, '`searchnums` DESC, `videonum` DESC', $page, $pagesize); $pages = $this->keyword_db->pages; //將原模板路徑 content 修改為新手機模板路徑 wap include template('wap', 'tag'); } /** * 按照模型搜索 */ public function lists() { $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']); $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); //下行代碼添加 catid, 并刪除 url, $res = $this->db->get_one(array('id'=>$contentid), 'catid, title, description, inputtime, style'); $res['title'] = str_replace($tag, '<font color="#f00">'.$tag.'</font>', $res['title']); $res['description'] = str_replace($tag, '<font color="#f00">'.$tag.'</font>', $res['description']); //此處為武林網(www.49028c.com)添加代碼開始 $catid = $res['catid']; $types = getcache('wap_type','wap'); foreach ($types as $type) { if($type['cat']==$catid) { $typeid = $type['typeid']; break; } } $res['url'] = WAP_SITEURL."&a=show&catid=".$catid."&typeid=".$typeid."&id=".$contentid; //此處為武林網(www.49028c.com)添加代碼結束 $datas[] = $res; } } $SEO = seo($siteid, '', $tag); //將原模板路徑 content 修改為新手機模板路徑 wap include template('wap','tag_list'); }}?>
轉載完畢,代碼361源碼沒有親測,有興趣的朋友可以自行測試,如果有問題請向我們反映。
以上就是PHPCMS二次開發wap手機站創建tags列表頁及調用教程的全部內容,希望對大家的學習和解決疑問有所幫助,也希望大家多多支持武林網。新聞熱點
疑難解答