phpcmsv9移动端页面静态化功能实现方法

2019-10-0108:00:32网站建设与开发Comments2,388 views字数 6828阅读模式

1、栏目添加、编辑相关实现方法修改文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

这里只需修改一个文件 phpcms/models/admin/category.php文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

a.栏目添加方法处理文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

在 category.php 中找到 public function add() 方法,把 add 方法中的文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

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'] = '';
    }}

修改为:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

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'];
    }
}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

//添加的内容
//移动端内容生成静态配置
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.栏目编辑方法处理文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

在 category.php 中找到 public function edit() 方法,把 edit方法中的文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

//栏目生成静态配置
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'] = '';
    }
}

修改为:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

//栏目生成静态配置
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'];
    }
}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

//添加的内容
//移动端内容生成静态配置
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、内容发布管理添加生成移动端内容页、栏目页功能文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

扩展——菜单管理——发布管理:添加子菜单文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

添加'批量更新移动端内容页'菜单:
菜单中文名:批量更新移动端内容页
英文名:create_content_html_m
模块名:content
文件名:create_html
方法名:show_m
添加'批量更新移动端栏目页'菜单:
菜单中文名:批量更新移动端栏目页
英文名:create_list_html_m
模块名:content
文件名:create_html
方法名:category_m

3、实现批量更新移动端内容页文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

①方法修改文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

复制 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;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

复制 phpcms/models/content/classes/html.class.php 中的 show 方法放到 show 方法之后,把 show 方法修改为 show_m,
修改 include template('content', $template); 为 include template('wap', $template);(wap为你应用的模板下存放移动站模板的文件夹名称,这里如果不修改,生成的页面用的是content里面的模板)

②模板修改文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

复制 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、实现批量更新移动端栏目页文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

①方法修改文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

复制 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里面的模板)

②模板修改文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

复制 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、发布管理添加生成移动端首页文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

扩展——菜单管理——发布管理:添加子菜单文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

添加 '生成移动端首页' 菜单:
菜单中文名:生成移动端首页
中文名: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的方法内容如下:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

public function index_m() {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

        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();文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

        include template('wap','index',$style);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

        return $this->createhtml($file, 1);
    }

到此移动端页面静态化基本完成了。当然了,这里只是实现页面静态化,对于生成的移动端页面里面的 url 这里就不做介绍了,因此,按照我这里分享的教程,最后生成的移动端页面里的 url 有可能是 pc 端的url,具体就要看你的模板是怎么处理的了。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

另外,在教程中用引用的模板是 wap 里的,也就是说你的模板里要有 wap 文件夹,且里面要有相应的模板。当然,你也可以把 wap 改成 content ,不过此时生成移动端页面是和移动端一样的,你也可以用这个方法来测试 是否可以生成移动端页面。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

同时,这个方法可以实现双模板,不知道聪明的你有没有发现呢?文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/16784.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/16784.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定