我们在使用织梦(dedecms)系统做网站的时候,有时候我们在做手机站的时候需要和PC站共用一个数据库,即PC站更新了文章,手机站也就随时更新,目前织梦的版本有这个功能,PC和手机的同时生成,这里我介绍的是之前使用wap.php实现的动态网址的方法,现在主要是把手机站详情页模板中的例子拿出来和大家分享,里面有文章翻页功能的实现这才是亮点。代码如下:
//文章页else if($action=='article'){ //调用某个栏目id为467下的文章 $dsql->SetQuery("Select id,title,litpic,description,pubdate From `dede_archives` where typeid='467' and channel=1 And arcrank = 0 order by id desc"); $i=0; $dsql->Execute(); while($row=$dsql->GetObject()) { $i++; $doctorlist .="<li> <a class='pic' href='wap.php?action=article&id={$row->id}' target='_blank'> <p>".cn_substr($row->description,140,0)."... <a href='wap.php?action=article&id={$row->id}' target='_blank' class='red'> 【详细】</a></p> <a onclick='openZoosUrl();LR_HideInvite();return false;' href='javascript:void(0);'> <img src='/wap_images/zj0{$i}.jpg' /></a> </li>"; } //文档信息 $query = " Select tp.typename,tp.ishidden,arc.typeid,arc.title,arc.arcrank, arc.pubdate,arc.writer,arc.click,addon.body From `dede_archives` arc left join `dede_arctype` tp on tp.id=arc.typeid left join `dede_addonarticle` addon on addon.aid=arc.id where arc.id='$id' "; $row = $dsql->GetOne($query,MYSQL_ASSOC); foreach($row as $k=>$v) $$k = $v; unset($row); $pubdate = MyDate("Y-m-d",$pubdate); if($arcrank!=0) exit(); $title = ConvertStr($title); $body = html2wml($body); if($ishidden==1) exit(); //当前栏目相关文章调用 $dsql->SetQuery("Select id,title,litpic,description,pubdate From `dede_archives` where typeid='$typeid' and channel=1 And arcrank = 0 order by id desc limit 4"); $dsql->Execute(); while($row=$dsql->GetObject()){ $xiangguan .= "<li><img src='/wap_images/xplx.png' alt='' /> <a href='wap.php?action=article&id={$row->id}' target='_blank'> ".cn_substr(($row->title),30,0)."</a> <span>".MyDate("Y-m-d",$row->pubdate)."</span> </li>"; } //获取同分类前一条的id和title(上一篇) $query = "Select id,title FROM `dede_archives` where id<'$id' AND typeid='$typeid' order by id desc limit 1"; $row = $dsql->GetOne($query,MYSQL_ASSOC); (!empty($row[id])) ? $prev_arc_id = $row[id] : $prev_arc_id = $id; (!empty($row[title])) ? $prev_arc_title= $row[title] : $prev_arc_title = $title; //获取同分类后一条的id和title(下一篇) $query = "Select id,title FROM `dede_archives` where id>'$id' AND typeid='$typeid' order by id asc limit 1"; $row = $dsql->GetOne($query,MYSQL_ASSOC); (!empty($row[id])) ? $next_arc_id = $row[id] : $next_arc_id = $id; (!empty($row[title])) ? $next_arc_title= $row[title] : $next_arc_title = $title; //栏目内容(分页输出) include($cfg_templets_dir."/wap/article.php"); $dsql->Close(); echo $pageBody; exit();}
对应的php文件内容是(article.php):
<!-- 文章内容 --> <div class="article"> <div class="article_bt"> <p><?php echo $title; ?></p> <span><?php echo $pubdate; ?></span> </div> <div class="article_nr"> <?php echo $body; ?> </div> <div class="fenye"> <ul> <li><img src="/wap_images/xplx.png" alt="" /> 上一篇:<a href="/wap.php?action=article&id=<?php echo $prev_arc_id;?>" target="_blank"><?php echo $prev_arc_title;?></a></li> <?php echo $channellistnext?> <li><img src="/wap_images/xplx.png" alt="" /> 下一篇:<a href="/wap.php?action=article&id=<?php echo $next_arc_id;?>" target="_blank"><?php echo $next_arc_title;?></a></li> </ul> </div> <div class="wyzx"> <ul> <li><a onclick="openZoosUrl();LR_HideInvite();return false;" href="javascript:void(0);"> <img src="/wap_images/wyzx01.jpg" alt="" /></a></li> <li><a onclick="openZoosUrl();LR_HideInvite();return false;" href="javascript:void(0);"> <img src="/wap_images/wyzx02.jpg" alt="" /></a></li> </ul> </div> <!-- 调用相关文章 --> <div class="xgwz"> <div class="weizhi"> 相关文章 </div> <div class="zzlist"> <ul> <?php echo $xiangguan;?> </ul> </div> </div> </div> <!--调用指定栏目id为467的文章--> <div class="bd"> <ul> <?php echo $doctorlist;?> </ul> </div>
如果本文对你有帮助,欢迎打赏本站