Dedecms 5.7 列表页点击加载更多读取数据库内容

 

HTML和JS代码:

<div style="background: #FFF;text-align: center;font-size: 14px;color:#6D6D6D;">
  <a href="javascript:;" id="getMore" pnum="2">点击浏览更多内容</a>
</div>
<script type="text/javascript">
 $("#getMore").click(function(){
 var _this = $(this), 
 pnum = _this.attr("pnum"),//分页码
 typeid = {dede:field name='typeid' /};// 栏目ID自动获取
 if(pnum == 0){
 return false;
 }
 $.ajax({
 url: '/plus/arcajax.php',
 data: {typeid:typeid,pnum:pnum},
 success: function(data){
 if(data != ''){
 $(".index-list").append(data);//数据显示到页面
 _this.attr("pnum", Number(pnum)+1);//分页+1
 }else{
 _this.text("没有更多的数据");
 _this.attr("pnum", 0)
 }
 }
 })
 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 = '<li class="mui-table-view-cell mui-media"><a href="view.php?aid=[field:id/]">
								[field:array runphp=\'yes\']@me = (strpos(@me[\'litpic\'],\'defaultpic\') ? "" : "<img src=\'{@me[\'litpic\']}\' class=\'mui-media-object mui-pull-left\'/>"); [/field:array]
	            <div class="mui-media-body">
	            	<p style="color: #000;font-size: 16px;height: 54px;overflow: hidden;white-space:normal">[field:title/]</p>
	                <p style="font-size:11px;">[field:writer/] | [field:pubdate function="MyDate(\'Y-m-d\',@me)"/]</p>
	            </div>
	        </a>
	   </li>';//加载模板,请自行修改
  //处理列表内容项
    $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).") 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();

 

使用方法:

1、加载是用AJAX,需要使用到jQuery;

2、模板在arcajax.php第二十八行请自行按需修改;

3、arcajax.php放到plus目录下。

原创文章,作者:管理员,如若转载,请注明出处:http://www.bajiege.com/soft/dedecms/dedecms-5-7-%e5%88%97%e8%a1%a8%e9%a1%b5%e7%82%b9%e5%87%bb%e5%8a%a0%e8%bd%bd%e6%9b%b4%e5%a4%9a%e8%af%bb%e5%8f%96%e6%95%b0%e6%8d%ae%e5%ba%93%e5%86%85%e5%ae%b9.html

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据