dedecms使用ajax调用指定栏目文章列表

15 年 7 月 3 日 星期五 (已编辑)
454 字
3 分钟

打开或复制一份plus目录下的list.php文件,在require_once(dirname( FILE).“/../include/common.inc.php”);

这段代码后加入以下代码:

| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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 '#@__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.sitepath FROM '#@__archives' as a JOIN '#@__arctype' AS t ON a.typeid=t.id $typesql ORDER BY id DESC LIMIT $start,$pagesize"; $dsql->SetQuery($sql); $dsql->Execute('list'); $statu = 0;//是否有数据,默认没有数据 $data = array(); } | | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | $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['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'], $row['namerule2'],$row['moresite'],$row['siteurl'],$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'] = ".$row[" typeurl'< span>]."'>".$row['typename']."";//分类链 $row['fulltitle'] = $row['title'];//完整的标题 $row['title'] = cn_substr($row['title'], 60);//截取后的标题 $data[$index] = $row; $index++; } if(!empty($data)){ $statu = 1;//有数据} $result =array('statu'=>$statu,'list'=>$data,'total'=>$total,'load_num'=>$load_num); echo json_encode($result);//返回数据exit(); | | ---------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

以上代码摘自: 百度经验

js代码输出获取到的内容:

| 1 2 3 4 5 6 7 8 9 10 | $('.btn').on("click",function(){ $("#content-box").hide(); $("#content-box").html("数据加载中..."); $("#content-box").show(); var htmlobj= $.ajax({ url:"/plus/list.php?tid="+$(this).attr("data-typeid"), async:false}); $("#content-box").html(htmlobj.responseText); }); | | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

欢迎关注我的其它发布渠道
公众号小程序

文章标题:dedecms使用ajax调用指定栏目文章列表

文章作者:bmqy

文章链接:https://bmqy.net/1501.html[复制]

最后修改时间:


商业转载请联系站长获得授权,非商业转载请注明本文出处及文章链接,您可以自由地在任何媒体以任何形式复制和分发作品,也可以修改和创作,但是分发衍生作品时必须采用相同的许可协议。
本文采用CC BY-NC-SA 4.0进行许可。