摘要:在教程中用引用的模板是 wap 里的,也就是说你的模板里要有 wap 文件夹,且里面要有相应的模板。当然,你也可以把 wap 改成 content ,不过此时生成移动端页面是和移动端一样的,你也可以用这个方法来测试 是否可以生成移动端页面。
1、栏目添加、编辑相关实现方法修改
这里只需修改一个文件 phpcms/models/admin/category.php
a.栏目添加方法处理
在 category.php 中找到 public function add() 方法,把 add 方法中的if($_POST['info']['type']!=2) {
//栏目生成静态配置
if($setting['ishtml']) {
$setting['category_ruleid'] = $_POST['category_html_ruleid'];
} else {
$setting['category_ruleid'] = $_POST['category_php_ruleid'];
$_POST['info']['url'] = '';
}
}
修改为:if($_POST['info']['type']!=2) {
//栏目生成静态配置
if($setting['ishtml']) {
$setting['category_ruleid'] = $_POST['category_html_ruleid'];
} else {
$setting['category_ruleid'] = $_POST['category_php_ruleid'];
$_POST['info']['url'] = '';
}
//添加的内容
//移动端生成静态配置
if ($setting['m_ishtml']){
$setting['m_category_ruleid'] = $_POST['m_category_html_ruleid'];
}else{
$setting['m_category_ruleid'] = $_POST['m_category_php_ruleid'];
}
}
//添加的内容
//移动端内容生成静态配置
if($setting['m_content_ishtml']) {
$setting['m_show_ruleid'] = $_POST['m_show_html_ruleid'];
} else {
$setting['m_show_ruleid'] = $_POST['m_show_php_ruleid'];
}
b.栏目编辑方法处理
在 category.php 中找到 public function edit() 方法,把 edit方法中的//栏目生成静态配置
if($_POST['type'] != 2) {
if($setting['ishtml']) {
$setting['category_ruleid'] = $_POST['category_html_ruleid'];
} else {
$setting['category_ruleid'] = $_POST['category_php_ruleid'];
$_POST['info']['url'] = '';
}
}
修改为://栏目生成静态配置
if($_POST['type'] != 2) {
if($setting['ishtml']) {
$setting['category_ruleid'] = $_POST['category_html_ruleid'];
} else {
$setting['category_ruleid'] = $_POST['category_php_ruleid'];
$_POST['info']['url'] = '';
}
//添加的内容
//移动端生成静态配置
if ($setting['m_ishtml']){
$setting['m_category_ruleid'] = $_POST['m_category_html_ruleid'];
}else{
$setting['m_category_ruleid'] = $_POST['m_category_php_ruleid'];
}
}
//添加的内容
//移动端内容生成静态配置
if($setting['m_content_ishtml']) {
$setting['m_show_ruleid'] = $_POST['m_show_html_ruleid'];
} else {
$setting['m_show_ruleid'] = $_POST['m_show_php_ruleid'];
}
2、内容发布管理添加生成移动端内容页、栏目页功能
扩展——菜单管理——发布管理:添加子菜单添加'批量更新移动端内容页'菜单:
菜单中文名:批量更新移动端内容页
英文名:create_content_html_m
模块名:content
文件名:create_html
方法名:show_m添加'批量更新移动端栏目页'菜单:
菜单中文名:批量更新移动端栏目页
英文名:create_list_html_m
模块名:content
文件名:create_html
方法名:category_m
3、实现批量更新移动端内容页
①方法修改复制 phpcms/models/content/create_html.php 中的 show 方法放到 show 方法之后,把 show 方法改为 show_m ,
修改 $urls = $this->url->show($r['id'], '', $r['catid'],$r['inputtime']);为 $urls = $this->url->show_m($r['id'], '', $r['catid'],$r['inputtime']); (有2处)
修改 $this->html->show($urls[1],$r,0,'edit',$r['upgrade']); 为 $this->html->show_m($urls[1],$r,0,'edit',$r['upgrade']); (有2处)
在 phpcms/models/content/classes/url.class.php 中,复制 show 方法放到 show 方法之后,把 show 方法改为 show_m ,
修改 $content_ishtml = $setting['content_ishtml']; 为 $content_ishtml = $setting['m_content_ishtml'];
修改 $show_ruleid = $setting['show_ruleid']; 为 $show_ruleid = $setting['m_show_ruleid'];
修改 $url_arr['content_ishtml'] = 1; 为 $url_arr['m_content_ishtml'] = 1;
复制 phpcms/models/content/classes/html.class.php 中的 show 方法放到 show 方法之后,把 show 方法修改为 show_m,
修改 include template('content', $template); 为 include template('wap', $template);(wap为你应用的模板下存放移动站模板的文件夹名称,这里如果不修改,生成的页面用的是content里面的模板)
②模板修改复制 phpcms/models/content/templates/create_html_show.tpl.php 文件到当前文件夹下,并重命名为 create_html_show_m.tpl.php
修改 create_html_show_m.tpl.php 文件 form 表达提交方法 ?m=content&c=create_html&a=show 为 ?m=content&c=create_html&a=show_m
修改 create_html_show_m.tpl.php 文件下面 JavaScript 中的 ?m=content&c=create_html&a=show&modelid 为 ?m=content&c=create_html&a=show_m&modelid
再次修改 phpcms/models/content/create_html.php 中的 show_m 方法,把此方法中所有的 ?m=content&c=create_html&a=show 修改成 ?m=content&c=create_html&a=show_m
修改此 show_m 方法末尾的模板应用 include $this->admin_tpl('create_html_show'); 为 include $this->admin_tpl('create_html_show_m');
4、实现批量更新移动端栏目页
①方法修改复制 phpcms/models/content/create_html.php 中的 category 方法放到原 category 方法后面,把 category 方法改为 category_m ,
修改 do..while 循环中的 $this->html->category($catid,$page); 为 $this->html->category_m($catid,$page);
复制 phpcms/models/content/classes/html.class.php 中的 category 方法放到 category 方法之后,把 category 方法修改为 category_m,
修改
if($parent_setting['ishtml']==0 && $setting['ishtml']==1){
$parentdir = $CATEGORYS[$CAT['parentid']]['catdir'].'/';
}
为
if($parent_setting['m_ishtml']==0 && $setting['m_ishtml']==1){
$parentdir = $CATEGORYS[$CAT['parentid']]['catdir'].'/';
}
修改 $base_file = $this->url->get_list_url($setting['category_ruleid'],$parentdir, $catdir, $catid, $page); 为 $base_file = $this->url->get_list_url($setting['m_category_ruleid'],$parentdir, $catdir, $catid, $page);
修改 include template('content',$template); 为 include template('wap',$template);(wap为你应用的模板下存放移动站模板的文件夹名称,这里如果不修改,生成的页面用的是content里面的模板)
②模板修改复制 phpcms/models/content/templates/create_html_category.tpl.php 文件到当前文件夹下,并重命名为 create_html_category_m.tpl.php
修改 create_html_category_m.tpl.php 文件 form 表达提交方法 ?m=content&c=create_html&a=category 为 ?m=content&c=create_html&a=category_m
修改 create_html_category_m.tpl.php 文件下面 JavaScript 中的 ?m=content&c=create_html&a=category&modelid 为 ?m=content&c=create_html&a=category_m&modelid
再次修改 phpcms/models/content/create_html.php 中的 category_m 方法,把此方法中所有的 ?m=content&c=create_html&a=category 修改成 ?m=content&c=create_html&a=category_m
修改此 show_m 方法末尾的模板应用 include $this->admin_tpl('create_html_category'); 为 include $this->admin_tpl('create_html_category_m');
5、发布管理添加生成移动端首页
扩展——菜单管理——发布管理:添加子菜单添加 '生成移动端首页' 菜单:
菜单中文名:生成移动端首页
中文名:index_m
模块名:content
文件名:create_html
方法名:public_index_m复制 phpcms/models/content/create_html.php 中的 public_index 方法放到 public_index 方法之后 ,修改方法名为 public_index_m,
修改 $size = $this->html->index(); 为 $size = $this->html->index_m();
复制 phpcms/model/content/classes/html.class.php 中的 index 方法放到 index 方法之后,并重命名为 index_m,
修改后的 index_m 方法内容如下:public function index_m() {
if($this->siteid==1) {
$file = PHPCMS_PATH.'m/index.html';
//添加到发布点队列
$this->queue->add_queue('edit','/m/index.html',$this->siteid);
} else {
$site_dir = $this->sitelist[$this->siteid]['dirname'];
$file = $this->html_root.'/'.$site_dir.'/m/index.html';
//添加到发布点队列
$this->queue->add_queue('edit',$file,$this->siteid);
$file = PHPCMS_PATH.$file;
}
define('SITEID', $this->siteid);
//SEO
$SEO = seo($this->siteid);
$siteid = $this->siteid;
$CATEGORYS = $this->categorys;
$style = $this->sitelist[$siteid]['default_style'];
ob_start();
include template('wap','index',$style);
return $this->createhtml($file, 1);
}
到此移动端页面静态化基本完成了。当然了,这里只是实现页面静态化,对于生成的移动端页面里面的 url 这里就不做介绍了,因此,按照我这里分享的教程,最后生成的移动端页面里的 url 有可能是 pc 端的url,具体就要看你的模板是怎么处理的了。
另外,在教程中用引用的模板是 wap 里的,也就是说你的模板里要有 wap 文件夹,且里面要有相应的模板。当然,你也可以把 wap 改成 content ,不过此时生成移动端页面是和移动端一样的,你也可以用这个方法来测试 是否可以生成移动端页面。
同时,这个方法可以实现双模板,不知道聪明的你有没有发现呢?
本次的教程分享到这就结束了,如果你有什么疑问可以在评论区留言,或者发电子邮件提问。