dedecms 首页点击加载更多,已验证OK
使用方法:
1、加载是用AJAX,需要先引用jQuery
2、模板在arcajax.php第二十八行请自行按需修改(修改$innertext的值)
3、arcajax.php放到plus目录下
HTML和js代码:
<div id="scrollDiv">
{dede:arclist titlelen='40' infolen='200' row='3'}
循环部分
{/dede:arclist}
</div>
<div id="loading27">加载中</div>
<a href="{dede:field name='typeurl'/}" class="morearticle" id="getMore" pnum="2">
点击加载更多
</a>
<script type="text/javascript">
$("#getMore").click(function() {
var _this = $(this),
pnum = _this.attr("pnum"), //分页码
typeid = 0; // 栏目ID
if (pnum == 0) {
return false;
}
$("#loading27").show();
$.ajax({
url: '/plus/arcajax.php',
data: {
typeid: typeid,
pnum: pnum
},
success: function(data) {
if (data != '') {
$("#scrollDiv").append(data); //数据显示到页面
_this.attr("pnum", Number(pnum) + 1); //分页+1
} else {
_this.text("没有更多的数据");
_this.attr("pnum", 0)
}
$("#loading27").hide();
}
})
return false;
})
</script>
PHP代码(arcajax.php):
<?php
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(DEDEINC.'/channelunit.class.php');
require_once(DEDEINC.'/taglib/arcpagelist.lib.php');
$pnum = empty($pnum)? 0 : intval(preg_replace("/[^\d]/",'', $pnum));
$typeid = empty($typeid)? 0 : intval(preg_replace("/[^\d]/",'', $typeid));
// if($typeid==0 || $pnum==0) die(" Request Error! ");
if($typeid >= 0){
$titlelen = AttDef($titlelen,30);
$infolen = AttDef($infolen,160);
$imgwidth = AttDef($imgwidth,120);
$imgheight = AttDef($imgheight,120);
$listtype = AttDef($listtype,'all');
$arcid = AttDef($arcid,0);
$channelid = AttDef($channelid,0);
$orderby = AttDef($orderby,'default');
$orderWay = AttDef($order,'desc');
$subday = AttDef($subday,0);
$line = $row;
$artlist = '';
//通过页面及总数解析当前页面数据范围
$strnum = ($pnum-1) * 12;
$limitsql = " LIMIT $strnum,12 ";
$innertext = '<div class="oli clearfix">
<a href="[field:arcurl/]" class="fl" title="[field:title/]">
<div class="oli_img">
<img src="[field:litpic/]" alt="[field:title/]" class="lazy" />
</div>
</a>
<div class="oli_font fr">
<h3><a href="[field:arcurl/]">[field:title/]</a></h3>
<div class="description">
<p>[field:info/]...</p>
</div>
<div class="clearfix">
<div class="data fl">
<p class="author">编辑:[field:writer /]</p>
<p class="date"><i></i><span>时间:[field:dtime function="GetDateMk(\'@me\')"/] </span></p>
<p class="see"><i></i><span>点击:[field:click/]</span></p>
</div>
</div>
</div>
</div>';//模板
//处理列表内容项
$query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,
tp.moresite,tp.siteurl,tp.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
WHERE arc.typeid IN (".GetSonIds($typeid).") And flag not like '%c%' And flag not like '%h%' ORDER BY arc.sortrank desc $limitsql";
$dsql->SetQuery($query);
$dsql->Execute('al');
$dtp2 = new DedeTagParse();
$dtp2->SetNameSpace('field', '[', ']');
$dtp2->LoadString($innertext);
$GLOBALS['autoindex'] = 0;
$ids = array();
for($i=0; $i<12; $i++) {
for($j=0; $j<1; $j++) {
if($row = $dsql->GetArray("al")) {
$ids[] = $row['id'];
//处理一些特殊字段
$row['info'] = $row['infos'] = cn_substr($row['description'],$infolen);
$row['id'] = $row['id'];
if($row['corank'] > 0 && $row['arcrank']==0) {
$row['arcrank'] = $row['corank'];
}
$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:\/\/#", $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'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
$row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".preg_replace("#['><]#", "", $row['title'])."'>";
$row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
$row['fulltitle'] = $row['title'];
$row['title'] = cn_substr($row['title'],$titlelen);
if($row['color']!='') $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
if(preg_match('#b#', $row['flag'])) $row['title'] = "<strong>".$row['title']."</strong>";
//$row['title'] = "<b>".$row['title']."</b>";
$row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
$row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
$row['memberurl'] = $GLOBALS['cfg_memberurl'];
$row['templeturl'] = $GLOBALS['cfg_templeturl'];
if(is_array($dtp2->CTags)) {
foreach($dtp2->CTags as $k=>$ctag) {
if($ctag->GetName()=='array') {
//传递整个数组,在runphp模式中有特殊作用
$dtp2->Assign($k,$row);
} else {
if(isset($row[$ctag->GetName()])) $dtp2->Assign($k,$row[$ctag->GetName()]);
else $dtp2->Assign($k,'');
}
}
$GLOBALS['autoindex']++;
}
$artlist .= $dtp2->GetResult()."\r\n";
}//if hasRow
else {
$artlist .= '';
}
}//Loop Col
}//loop line
$dsql->FreeResult("al");
} else{
die(" Request Error! ");
}
AjaxHead();
echo $artlist;
exit();
(参考:https://zhidao.baidu.com/question/362009556124966812.html?fr=iks&word=arcajax.php&ie=gbk,有修改)