一、前端代码:
(1)创建单页面控制器
打开phpcms/modules/wap/index.php ,在最下边增加控制器:
代码中的L('info_does_not_exists'),需要你去phpcmslanguageszh-cnwap.lang.php增加代码:
- //单页面
- function page() {
- $WAP = $this->wap;
- $TYPE = $this->types;
- $WAP_SETTING = string2array($WAP['setting']);
- $GLOBALS['siteid'] = max($this->siteid,1);
- //$typeid = intval($_GET['typeid']);
- $catid = intval($_GET['catid']);
- if(!$catid) exit(L('parameter_error'));
- //$catid = $this->types[$typeid]['cat'];
- $this->page_db = pc_base::load_model('page_model');
- $data = $this->page_db->get_one(array('catid'=>$catid));
- if(!$data) showmessage(L('info_does_not_exists'),'blank');
- extract($data);
- include template('wap', 'page');
- }
(2)创建对应模板
- $LANG['info_does_not_exists'] = '您要查看的信息不存在或者还未通过审批!';
在phpcmstemplatesdefaultwap下创建模板page.html,该模板调用方式和普通内页调用标签一样
二、后端代码
(1)修改代码让后台添加栏目时候显示单页面
打开phpcmsmoduleswapwap_admin.php 首页现在11行之后增加代码:
然后在大概120行找到:
- $CATEGORYS = getcache('category_content_'.$siteid,'commons');//pc栏目缓存
改成:$r['select_cat'] = form::select_category('',$r[cat],'name="cat['.$r['typeid'].']"',L('wap_type_bound'),0,0,0,$siteid);
再然后找到大概208行:
- $r['select_cat'] = form::select_category('',$r[cat],'name="cat['.$r['typeid'].']"',L('wap_type_bound'),0,-1,0,$siteid);
改成:
- echo form::select_category('',0,'name="addcat['.$parentid.'][]"',L('wap_type_bound'),0,0,0,$siteid);
- echo form::select_category('',0,'name="addcat['.$parentid.'][]"',L('wap_type_bound'),0,-1,0,$siteid);
(2)找到文件phpcmsmoduleswaptemplatestype_manage.tpl.php的大概第9行
(3)修改数据库v9_wap_type,增加字段type,类型:tinyint,默认:0,0表示栏目, 1表示单页面
(为了方便以后使用,你可以直接在wap/install/wap.sql的第20行增加:`type` tinyint(1) DEFAULT '0', 方便以后可以直接使用)
(4)再次找到文件phpcmsmoduleswaptemplatestype_admin.tpl.php的
- $CATEGORYS = getcache('category_content_'.$siteid,'commons');//pc栏目缓存
后加入判断栏目性质代码:
- $info['cat'] = $_POST['info']['cat'] ? $_POST['info']['cat'] : showmessage(L('wap_empty_bound_type'),HTTP_REFERER);
在140行修改整个type_edit控制器改为
- /*判断栏目类型*/
- foreach ($CATEGORYS as $k => $cats) {
- if($cats['catid']== $info['cat']) {
- $info['type'] = intval($cats['type']);//栏目类型
- break;
- }
- }
- function type_edit() {
- $siteid = intval($_GET['siteid']);
- $CATEGORYS = getcache('category_content_'.$siteid,'commons');//pc栏目缓存
- if($_POST['dosubmit']) {
- $typename = $_POST['typename'];
- $types = 1;
- foreach ($typename as $typeid=>$in) {
- /*判断栏目类型*/
- foreach ($CATEGORYS as $k) {
- if($k['catid']== $_POST['cat'][$typeid]) {
- $types = intval($k['type']);//栏目类型
- break;
- }
- }
- $this->type_db->update(array(
- 'typename'=>$_POST['typename'][$typeid],
- 'cat'=>$_POST['cat'][$typeid],
- 'listorder'=>$_POST['listorders'][$typeid],
- 'type'=>$types,
- ),array('typeid'=>$typeid));
- }
- $addtype = $_POST['addtype'];
- $addcat = $_POST['addcat'];
- $addorder = $_POST['addorder'];
- if(is_array($addtype) && !empty($addtype)) {
- foreach ($addtype as $_k=>$_v) {
- foreach ($_v as $_s=>$infos) {
- $info['typename'] = $infos;
- $info['parentid'] = $_k;
- $info['siteid'] = $siteid;
- $info['cat'] = $addcat[$_k][$_s];
- $info['listorder'] = $addorder[$_k][$_s];
- foreach ($CATEGORYS as $k) {
- if($k['catid']== $_info['cat']) {
- $types = intval($k['type']);//栏目类型
- break;
- }
- }
- $info['type'] = $types;
- if($this->type_db->get_one(array('cat'=>$info['cat'],'siteid'=>$siteid))) {
- showmessage($info['typename'].L('wap_repeat_bound'),HTTP_REFERER);
- } else {
- $this->type_db->insert($info);
- }
- }
- unset($info);
- }
- }
- $this->type_cache($siteid);
- showmessage(L('operation_success'),HTTP_REFERER);
- }
- }
(5)修改全局函数,找到:phpcmsmoduleswapfunctionsglobal.func.php
找到:
改成:
- /**
- * 解析分类url路径
- */
- function list_url($typeid) {
- return WAP_SITEURL."&a=lists&typeid=$typeid";
- }
找到:
- /**
- * 解析分类url路径
- */
- function list_url($typeid) {
- $siteid = $GLOBALS['siteid'];
- $types = getcache('wap_type','wap');
- $CATEGORYS = getcache('category_content_'.$siteid,'commons');
- foreach ($types as $type) {
- if($type['typeid']== $typeid) {
- $cattype = intval($type['type']);//栏目类型
- $catid = intval($type['cat']);//对应catid
- break;
- }
- }
- if($cattype){
- return WAP_SITEURL."&c=index&a=page&catid=$catid";
- }else{
- return WAP_SITEURL."&a=lists&typeid=$typeid";
- }
- }
改成:
- /**
- * 解析内容url路径
- * $catid 栏目id
- * $typeid wap分类id
- * $id 文章id
- */
- function show_url($catid, $id, $typeid='') {
- global $WAP;
- if($typeid=='') {
- $types = getcache('wap_type','wap');
- foreach ($types as $type) {
- if($type['cat']==$catid) {
- $typeid = $type['typeid'];
- break;
- }
- }
- }
- return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";
- }
- /**
- * 解析内容url路径
- * $catid 栏目id
- * $typeid wap分类id
- * $id 文章id
- */
- function show_url($catid, $id, $typeid='') {
- global $WAP;
- if($typeid=='') {
- $types = getcache('wap_type','wap');
- foreach ($types as $k => $type) {
- if($type['cat']==$catid) {
- //$typeid = $type['typeid'];
- $cattype = intval($type['type']);
- break;
- }
- }
- }
- if($cattype){
- return WAP_SITEURL."&c=index&a=page&catid=$catid";
- }else{
- return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";
- }
- }
全部修改完之后,一定一起要记得更新全站缓存,这样就可以绑定单页面,并且可以自动跳转对应的url,
代码有点多,不知道有没有说清楚,如有什么疑问,可以给我留言,因为我做了其他的开发,就不直接打包放出源码了!