AJAX异步加载的弊端:属于WEB前端技术,蜘蛛不会抓Js调用的内容,也就是并不利于SEO优化。所以要运用这个功能的话最好有一部分直接调用,另一部分采用AJAX异步加载。
接下来用织梦来做AJAX异步加载WEB前端开发。网上有诸多教程,经过笔者整理,给出详细说明,修正后分享给大家。
打开/plus/List.PHP,找到
require_once(dirname(__file__)."/../include/common.inc.PHP");
下面增加代码
if(isset($_GET['AJAX'])){$typeID = isset($_GET['typeID']) ? intval($_GET['typeID']): 0;//传递过来的分类ID$page = isset($_GET['page']) ? intval($_GET['page']): 0;//页码$pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']): 15;//每页多少条,也就是一次加载多少条数据$start = $page>0 ? ($page-1)*$pagesize : 0;//数据获取的起始位置。即limit条件的第一个参数。$typesql = $typeID ? " WHERE typeID=$typeID" : '';//这个是用于首页实现瀑布流加载,因为首页加载数据是无需分类的,所以要加以判断,如果无需$total_sql = "SELECT COUNT(ID) as num FROM `dede_archives` $typesql ";$temp = $dsql->Getone($total_sql);$total = 0;//数据总数$load_num =0;if(is_array($temp)){$load_num= round(($temp['num']-15)/$pagesize);//要加载的次数,因为默认已经加载了$total = $temp['num'];}$sql = "SELECT a.*,t.typedir,t.typename,t.isdefault,t.defaultname,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepathFROM `dede_archives` as a JOIN `dede_arctype` AS t ON a.typeID=t.ID $typesql ORDER BY ID DESC liMIT $start,$pagesize";//echo "$sql";$dsql->Setquery($sql);$dsql->Execute('List');$statu = 0;//是否有数据,默认没有数据$data = array();$index = 0;while($row = $dsql->GetArray("List")){$row['info'] = $row['info'] = $row['infos'] = cn_substr($row['description'],160);$row['ID'] = $row['ID'];$row['filename'] = $row['arcurl'] = GetfileUrl($row['ID'],$row['typeID'],$row['senddate'],$row['Title'],$row['ismake'],$row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);$row['typeurl'] = GetTypeUrl($row['typeID'],$row['isdefault'],$row['defaultname'],$row['ispart'],$row['namerule2'],$row['sitepath']);if($row['litpic'] == '-' || $row['litpic'] == ''){$row['litpic'] = $GLOBALS['cfg_CMSpath'].'/images/defaultpic.gif';}if(!preg_match("#^http://#i",$row['litpic']) &&$GLOBALS['cfg_multi_site'] == 'Y'){$row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];}$row['picname'] = $row['litpic'];//缩略图$row['stime'] = GetDateMK($row['pubdate']);$row['typelink'] = "href='".$row['typeurl']."'>".$row['typename']." |
总结 |
评论列表(0条)