|
本帖最后由 服务器之家 于 2015-12-10 22:57 编辑
我十分理解不了WC为什么不在原版程序里改进,这样非官方的HACK在日后维护是非常麻烦的。
原理大概就是这样,程序里有几个生成函数(暂称makexxx),比如首页,列表,内容。
那么就
function makexxx(){
foreach(array(0, 1) as $is_mobile){
makexxx_do();// 0的时候生成PC端,1的时候生成移动端
}
}
===============================================
详细步骤
1)后台添加变量:
变量名: mobile_tpl_id, 标识: 手机端模板ID, 写入缓存
2)要注意PC和移动端模板ID一定要一一对应,不对应的要修改数据库表的ID
封面模板 phome_enewsclasstemp和phome_enewsclasstemp_x(x为数字)
列表模板 phome_enewslisttemp和phome_enewslisttemp_x(x为数字)
内容模板 phome_enewsnewstemp和phome_enewsnewstemp_x(x为数字)
其他还有几个,用到的话,自己找下。
3)在/e/class/functions.php文件最后面添加进下面的代码,注意注意,下面的代码里出现的函数,把原程序里相同的函数都在函数名末尾加一个_bak。比如程序里原来的
function ListHtml($classid,$fields,$enews=0,$userlistr=""){
要改成
function ListHtml_bak($classid,$fields,$enews=0,$userlistr=""){
- // ================================= 增加代码 =================================
- // 不方便传递参数的时候,使用全局变量,0为PC端,1为移动端
- $current_port = 0;
- function get_port(){
- global $current_port;
- return $current_port;
- }
- function set_port($val){
- global $current_port;
- $current_port = $val;
- }
- //刷新首页
- function ReIndex(){
- foreach(array(0,1) as $is_mobile){
- set_port($is_mobile);
- $indextemp=GetIndextemp($is_mobile);//取得模板
- NewsBq($classid,$indextemp,1,0);
- }
- printerror("ReIndexSuccess","history.go(-1)");
- }
- //模板表转换
- function GetTemptb($temptb){
- global $public_r,$dbtbpre;
- if(get_port()){
- $tempid = $public_r['add_mobile_tpl_id'];
- }else{
- $tempid=$public_r['deftempid'];
- }
- if(!empty($tempid)&&$tempid!=1)
- {
- $en="_".$tempid;
- }
- return $dbtbpre.$temptb.$en;
- }
- //返回当前根目录
- function eReturnTrueEcmsPath(){
- if(get_port()){
- $add_path = "/mobile/";
- }else{
- $add_path = "";
- }
- if(defined('ECMS_SELFPATH'))
- {
- return ECMS_SELFPATH.$add_path;
- }
- else
- {
- return ECMS_PATH.$add_path;
- }
- }
- //写文件
- function WriteFiletext($filepath,$string,$strip=TRUE){
- global $public_r;
- if($strip){
- $string=stripSlashes($string);
- }
- $dir = dirname($filepath);
- if(!file_exists($dir) && !mkdir($dir, true)){
- exit("创建目录失败({$dir})");
- }
- if(!chmod($dir,0777)){
- exit("修改目录权限失败({$dir})");
- }
- if(!file_put_contents($filepath, $string)){
- exit("写入文件失败({$filepath})");
- }
- @chmod($filepath,0666);
- }
- //写文件
- function WriteFiletext_n($filepath,$string){
- WriteFiletext($filepath,$string,FALSE);
- }
- //生成列表
- function ListHtml($classid,$fields,$enews=0,$userlistr=""){
- foreach(array(0,1) as $is_mobile){
- set_port($is_mobile);
- ListHtml_bak($classid,$fields,$enews=0,$userlistr="");
- }
- }
- //生成内容文件
- function GetHtml($classid,$id,$add,$ecms=0,$doall=0){
- foreach(array(0,1) as $is_mobile){
- set_port($is_mobile);
- GetHtml_bak($classid,$id,$add,$ecms=0,$doall=0);
- }
- }
复制代码
4)移动端生成的目录在主站根目录下的mobile目录。把css等模板文件放在这里就OK了。
首页和列表和文章页的完成了,其他的,再搞个自定义列表,还有别的需要搞么?
|
评分
-
查看全部评分
|