这篇文章主要为大家详细介绍了PHPCMS二次开发wap手机站创建tags列表页及调用教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴。
本文是361源码今天早上起床后看到的一篇文章,感觉有参考价值,就转载过来了,如有版权,请联系本站处理。
用PHPCMS创建了PC站的tags汇总页和列表页,通过统计观察效果还不错,有不少人访问,因此想在移动端手机站上也创建tags汇总页和列表页,可是默认只能在 phpcms emplatesdefaultcontent 创建一个tag.html和tag_list.html页面,在PC端用了移动端就用不了了,361源码网站长思考了下,能不能在移动端 phpcms emplatesdefaultwap 目录下也创建一个tag.html和tag_list.html 页面来实现呢?下面就是361源码网站长的实现方法,希望对有需要的朋友有所帮助。
1、将 phpcmsmodulescontent ag.php 文件拷贝到 phpcmsmoduleswap 目录下
2、打 phpcmsmoduleswap ag.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, ''.$tag.'', $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}{$keyword}{/loop}
4、在 phpcms emplatesdefaultwap 目录下创建 tag.html 即为tags汇总页 tag_list.html 即为tags列表页
5、tag.html调用标签示例:{loop $infos $info}
{$info['keyword']}({$info['videonum']})
{/loop}
6、tag_list.html调用标签示例:
{loop $datas $r}
{date('Y-m-d H:i:s',$r[inputtime])}· {$r[title]}{/loop}
7、phpcmsmoduleswap ag.php 文件完整展示<?php
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, ''.$tag.'', $res['title']);
$res['description'] = str_replace($tag, ''.$tag.'', $res['description']);
//此处为361源码网(www.ke361.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;
//此处为361源码网(www.ke361.com)添加代码结束
$datas[] = $res;
}
}
$SEO = seo($siteid, '', $tag);
//将原模板路径 content 修改为新手机模板路径 wap
include template('wap','tag_list');
}
}
?>
转载完毕,代码361源码没有亲测,有兴趣的朋友可以自行测试,如果有问题请向我们反映。
以上就是PHPCMS二次开发wap手机站创建tags列表页及调用教程的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持361模板网。