PHPCMS v9 手机端栏目绑定模板

phpcms的手机端,模块是有了,但是有些地方用的还不是很舒服,其中移动端栏目无法绑定模板就不是很方便。如图,所有的栏目绑定的模板是固定的

 

这次咱们就来处理下,移动端如何设置相应的模板。

这里说是设置模板其实有点伪命题,因为设置模板需要开发不少东西,就像phpcms的栏目那样,自己选择模板来绑定,我们这里为了快速、方便有更简单的方法。

我们让移动端的栏目和pc端的栏目绑定一样的模板,这里说绑定一样的模板指的是绑定同样的模板名字。

phpcms pc端模板路径 phpcms\templates\default\content   默认的文件有这些

如果你pc端的栏目绑定模板规则如下:

  • 图片                 category_picyure.html
    • 美女图片               list_picture.html  ----->内容页模板  show_picture.html
    • 帅哥图片               list_picture.html       ----->内容页模板  show_picture.html

 那么移动端的绑定结果如下  \phpcms\templates\default\wap 

  • 图片                 category_picyure.html
    • 美女图片               list_picture.html  ----->内容页模板  show_picture.html
    • 帅哥图片               list_picture.html       ----->内容页模板  show_picture.html

 你只需要在移动端的模板里面添加相应的模板文件,移动端栏目就能自动绑定。

下面是具体的代码修改

1、因为移动端首页模板绑定的是wap\index.html,所以不做修改。

2、打开\phpcms\modules\wap\index.php

  在方法 lists 中,约47行$template = ($TYPE[$typeid]['parentid']==0 && in_array($typeid,array_unique($parentids))) ? $WAP_SETTING['category_template'] : $WAP_SETTING['list_template']; 将其注释

  然后添加代码

/*$template = ($TYPE[$typeid]['parentid']==0 && in_array($typeid,array_unique($parentids))) ? $WAP_SETTING['category_template'] : $WAP_SETTING['list_template'];    */

        // 改造wap的默认模板  使其跟随pc模板规则走
        $setting = string2array($setting);
        $template = $setting['category_template'] ? $setting['category_template'] : 'category';
        $template_list = $setting['list_template'] ? $setting['list_template'] : 'list';
        $template = $child ? $template : $template_list;
        // 改造结束

        // 重新组装数据 让catgory的模板也能用
        if($child){
            $catids_str = $arrchildid;
            $pos = strpos($catids_str,',')+1;
            $catids_str = substr($catids_str, $pos);
            $sql = "status=99 AND catid IN ($catids_str)";
            $list = $this->db->select($sql, '*', $offset.','.$pagesize,'inputtime DESC');
            $total = $this->db->count($sql);
        }else{
            $list = $this->db->select(array('status'=>'99','catid'=>$catid), '*', $offset.','.$pagesize,'inputtime DESC');
        }
        //重新组装数据结束

 

  这样category 和list 都绑定了相应的栏目模板。其中数据就是 $list。 你可以使用$list进行遍历。

3、打开\phpcms\modules\wap\index.php

  在方法 show中约206行 $template = $WAP_SETTING['show_template'] ? $WAP_SETTING['show_template'] : 'show'; 将其注释

//$template = $WAP_SETTING['show_template'] ? $WAP_SETTING['show_template'] : 'show';
//处理模板调用
  $template = $CAT['setting']['show_template'] ? $CAT['setting']['show_template'] : 'show';

 ok 这样phpcms的移动端就处理完成了!

本文由 襄阳艾特网络  http://www.xyat.cn 原创,转载请注明出处。

posted @ 2018-11-12 17:07  吴宗怡  阅读(1333)  评论(2编辑  收藏  举报