phpcms手机站的个人总结

公司的网站是基于phpcms v9的,最近让我弄手机网站,之前的就是手机站就是pc网站的左半边。于是我摸索着弄出来了。
以下是我的总结
  • 1 首先要在手机端访问网站时自动识别,于是在phpcms/libs/functions/extention.func.php目录下添加一下代码
  function isMobile() {
  // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
    return true;
  }
  // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
  if (isset($_SERVER['HTTP_VIA'])) {
    // 找不到为flase,否则为true
    return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  }
  // 脑残法,判断手机发送的客户端标志,兼容性有待提高。其中'MicroMessenger'是电脑微信
  if (isset($_SERVER['HTTP_USER_AGENT'])) {
    $clientkeywords = array('nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile','MicroMessenger');
    // 从HTTP_USER_AGENT中查找手机浏览器的关键字
    if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
      return true;
    }
  }
  // 协议法,因为有可能不准确,放到最后判断
  if (isset ($_SERVER['HTTP_ACCEPT'])) {
   // 如果只支持wml并且不支持html那一定是移动设备
    // 如果支持wml和html但是wml在html之前则是移动设备
    if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
      return true;
    }
  }
  return false;
}
  • 2.接着在phpcms/modules/content/index.php中修改
    include template('content','index',$default_style);
    变成
if (ismobile()) {
                include template('wap', 'index',$default_style);
            } else {
                include template('content', 'index',$default_style);
            }

修改所有的
include template('content',$template);
变成

if (isMobile()) {
                include template('wap', $template);
            } else {
                include template('content', $template);
            }
 }
  • 接着就可在phpcms/template/default/wap文件夹里写手机端代码了
  • 还有要记得在后台模块/手机门户开启,并进行分类管理,与pc端进行关联,这样pc端内容更新,wap端也会更新

具体代码这里就不细说了
一下是我用到的一些方法

  • 这是直接调用对应的typeid
    <a href="index.php?m=wap&c=index&a=lists&typeid=4" target="_blank">

  • 这里是调用推荐位对应posid

{pc:content  action="position" posid="2" order="id DESC"  num="8"}            
            {loop $data $r}
            <li ><img src="static/picture/zg_li.gif"> <a href="index.php?m=wap&c=index&a=show&catid={$r['catid']}&id={$r['id']}" target="_blank">{str_cut($r['title'],65)}</a></li>
            {/loop}  
            {/pc} 
  • 这里是调用category.html栏目页调用
{loop subtype($typeid) $_s}<a href="index.php?m=wap&c=index&a=lists&typeid={$_s['typeid']}">{$_s[typename]}</a>{/loop}

这里调用对应pc端门户的catid

 {pc:content  action="lists" catid="23" order="listorder DESC"  start="0" num="8"}            
            {loop $data $r}
            <li > <a href="index.php?m=wap&c=index&a=show&catid={$r['catid']}&id={$r['id']}" target="_blank">{str_cut($r['title'],65)}</a></li>
            {/loop}  
            {/pc} 	

获取当前栏目父名称

{$CATEGORYS[$CAT[parentid]][catname]}

获取pc端当前栏目id

{$catid}

获取手机端当前栏目id

{$typeid}

获取当前栏目名称

{$CAT[catname]}或{$CATEGORYS[$catid][catname]}

获取当前栏目路径

{$CAT[url]}或{$CATEGORYS[$CAT[url]}

#######上级栏目的名称

{$CATEGORYS[$CAT[parentid]][catname]}

调用栏目名

{pc:content action="category" catid="$catid"  num="4"siteid="$siteid" order="id ASC"}
      {loop $data $r}
      
            <li class="fl"><a href="{$r[url]}"><span>{$r[catname]}</span></a></li>
       {/loop}
{/pc}

调用文章列表

 {pc:content  action="lists" catid="15" order="listorder DESC"  num="8"}
            
            {loop $data $r}
            <li ><img src="static/picture/zg_li.gif"> <a href="index.php?m=wap&c=index&a=show&catid={$r['catid']}&id={$r['id']}" target="_blank">{str_cut($r['title'],65)}</a></li>
            {/loop}  
            {/pc} 
loop循环里的名称
{$r[catname]}   

同级调用

(1)单网页:
     {loop $arrchild_arr $cid}<!--只适应用单网页-->
<li {if $catid==$cid}class="cur_link"{/if}><a href="{$CATEGORYS[$cid][url]}/">{$CATEGORYS[$cid][catname]}</a></li>
{/loop}
  (2)模型列表页:
      {pc:content action="category" catid="$parentid" num="25" siteid="$siteid" order="listorder ASC"}
 <ul>
 {loop $data $r}
    <li {if $catid==$r[catid]}class="cur_link"{/if}><a href="{$r[url]}/">{$r[catname]}</a></li>
 {/loop}
 </ul>
 {/pc}
  (3)内容页:
       {pc:content action="category" catid="$top_parentid" num="25" siteid="$siteid" order="listorder ASC"}
 <ul>
 {loop $data $r}
    <li {if $catid==$r[catid]}class="cur_link"{/if}><a href="{$r[url]}/">{$r[catname]}</a></li>
 {/loop}
 </ul>
 {/pc}

子栏目调用

category.html 写以下代码
{loop subcat($catid) $r}
		 <ul>
		<li><a href="{$r[url]}" title="{$r[catname]}">{$r[catname]}</a></li>
		</ul>
	{/loop}
list.html 写以下代码
  {loop subcat($catid) $r}
 <ul>
<li><a href="{$CATEGORYS[$r[catid]][url]}">{$CATEGORYS[$r[catid]][catname]}</a></li>
</ul>
{/loop}

调用手机子栏目

{pc:get sql="select * from juyou_wap_type where parentid in(4)" order="listorder ASC"  return="data"}
{loop $data $r}
<a href="index.php?m=wap&c=index&a=lists&typeid={$r['typeid']}">{$r['typename']}</a>
{/loop}
  {/pc}
{$r[catname]}获取循环中的数据
{$[catname]}获取当前栏目名称

子type的调用(catagory.html页面)

{loop subtype($typeid) $_s}<a href="index.php?m=wap&c=index&a=lists&typeid={$_s['typeid']}">{$_s[typename]}</a>{/loop}

PHPCMS_v9 wap不同列表采用不同模板的方法

1.在phpcms\modules\wap\index.php中搜索
?1$template = ($TYPE[$typeid]['parentid']==0 && in_array($typeid,array_unique($parentids))) ? $WAP_SETTING['category_template'] : $WAP_SETTING['list_template'];
修改为
?1$template = ($TYPE[$typeid]['parentid']==0 && in_array($typeid,array_unique($parentids))) ? $WAP_SETTING['category_template'] : $WAP_SETTING['list_template'].$typeid;
2.这样子的话,假定列表文件默认为list.html, 那typeid 为1的列表文件就是list1.html,typeid 为2的列表文件就是list2.html,这样子就可以不同列表采用不同模板显示。

limit用法

{pc:content action="lists" catid="15" order="id DESC" start='0' num="3"}

phpcms v9 wap内容页内容显示方法

phpcms v9的wap手机门户的问题解决
默认的{$content}标签假如内容页一开始输入的不是html代码的话会出现调用不出来的情况,
这里用{$rs['content']}   来调用则可以解决问题。
{APP_PATH} 这是首页地址
href="{$CATEGORYS[21]['url']}"这是栏目地址
{date('m-d',$r[updatetime])}   这是更新时间
{date('m-d',$r[inputtime])} 这是创建时间  
{$CATEGORYS[$CAT[parentid]][catname]}>{$CAT[catname]} 
这是父栏目和当前栏目的名字

更新

在V9中,表单向导提交后返回的是网站首页,极为不爽,现改为返回上一页:
修改方法:
打开:
phpcms\modules\formguide\index.php
public function show里找到showmessage(L('thanks'), APP_ PATH); //大概在78行
改为: showmessage(L(' thanks'), HTTP_ REFERER);
大功告成!

在这里插入图片描述

手机端的伪静态还没弄,等公司要求再弄吧,到时候我会更新的,毕竟要留点活给自己干

如果有问题,请大家指证,有什么困难也可以联系我
ps:电脑端的静态页面如果跳转到wap端
需要在template模板中添加

    function browserRedirect() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
    //跳转移动端页面
    window.location.href="http://m.ahkds.com/index.php?m=content&c=index&a=show&catid=35&id=23635";
    } 
        
    }
    browserRedirect(); 
    </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值