帝国cms 加载更多升级版

加载更多博主曾经多次折腾最终得出以下两个版本 适用于大多数项目
至于加载更多的gif 图片 请自己找素材吧
JS 调用部分 (栏目设置中 最好显示12条数据 匹配js拉取数据 且不重复  也可以自行设置测试条数)
本例按当前栏目拉取 适合列表页
容器和显示按钮showajaxnews
  1. <ul id="showajaxnews">
  2. [!--empirenews.listtemp--]
  3. [!--empirenews.listtemp--]
  4. <a class="go-more" id="loadmore">加载更多
后端数据结构 (/e/action/getmore.php)
  1. <?php
  2. require('../class/connect.php');
  3. require('../class/db_sql.php');
  4. require('../data/dbcache/class.php');
  5. if($_POST[action] == 'getmorenews'){
  6. $table=htmlspecialchars($_POST[table]);
  7. if(empty($_POST[orderby])){$orderby='newstime';}else{ $orderby=htmlspecialchars($_POST[orderby]);}
  8. if(empty($_POST[myorder])){$myorder='desc';}else{ $myorder='asc';}
  9. if(empty($_POST[limit])){$limit=12;}else{ $limit=(int)$_POST[limit];}
  10. if(empty($_POST[classid])){$where=null;}else{ $where='where classid in('.$_POST[classid].')';}
  11. if(empty($_POST[length])){$length=50;}else{ $length=(int)$_POST[length];}
  12. if(empty($_POST[small_length])){$small_length=500;}else{ $small_length=(int)$_POST[small_length];}
  13. $link=db_connect();
  14. $empire=new mysqlquery();
  15. $num =(int)$POST['next'] $limit;
  16. if($table){
  17. $sql=$empire->query("SELECT FROM `".$dbtbpre."ecms".$table."` $where order by $orderby $myorder limit $num,$limit");
  18. while($r=$empire->fetch($sql)){
  19. if($r[mtitlepic]==''){
  20. $r[mtitlepic]=$public_r[news.url]."e/data/images/notimg.gif";
  21. }
  22. $oldtitle=stripSlashes($r[title]);
  23. $title=sub($oldtitle,'',$length);
  24. $smalltext=stripSlashes($r[smalltext]);
  25. $smalltext=sub($smalltext,'',$small_length);
  26. $classname=$class_r[$r[classid]][classname];
  27. $newsurl=$public_r[newsurl];
  28. $classurl=$newsurl.$class_r[$r[classid]][classpath];
  29. $urls = sys_ReturnBqTitleLink($r);
  30. ?>
  31. <a href="<?=$urls?>">
  32. <div class="media-image">
  33. <img src="/miss.png"pun"><?=$r[mtitlepic]?>" alt="<?=$r[title]?>" width=60 height=60 />
  • <div class="media-content">
  • <h3 class="title"><?=$r[title]?>
  • <p class="meta">
  • <span class="meta-time"><?=date("Y-m-d",$r[newstime])?>
  • <?php
  • }
  • }
  • }
  • db_close();
  • $empire=null;
  • ?>
  • 另一个版本 点击后再拉取数据 适合首页等部位按制定栏目拉取
    1. $(function(){
    2. var i = 1; //设置当前页数
    3. $('#loadmore').click(function(){
    4. $.ajax({
    5. url : 'http://m.zhaohuati.com/e/action/getmore.php',
    6. type:'POST',
    7. data:{"next":i,'table':'news','classid':'14','action':'getmorenews','limit':12,'small_length':120},
    8. dataType : 'html',
    9. beforeSend:function(){
    10. $("#loadmore").show().html('<img src="/images/loaduai.gif" width=23/> 正在努力加载中...');
    11. $('#loadmore').attr('disabled','disabled');
    12. },
    13. success : function(data){
    14. if(data){
    15. $("#showajaxnews").append(data);
    16. $("#loadmore").removeAttr('disabled');
    17. $("#loadmore").html('点击加载更多');
    18. i++;
    19. }else{
    20. $("#loadmore").show().html("已全部加载完毕!");
    21. $('#loadmore').attr('disabled','disabled');
    22. return false;
    23. }
    24. }
    25. });
    26. });
    27. });
    注意:
    1. next:第几页
    2. table:调用数据表
    3. limit:每次调用数量
    4. small_length:简介截取字符数
    5. length:标题截取字符数
    6. classid:调用栏目,允许多个,如1,2,3,4 特别注意,必须是调用同一数据表的栏目
    7. orderby:排序,默认是newstime,传什么就按什么来排序,如 id
    8. myorder:正反序,默认是asc,传值怎为desc
    本项目需要引入jq
    博主使用的是jquery-1.8.3.min.js   使用者可以自行测试版本
    不提供JQ文件

    后来对这个功能的需求又升级了  可以参考
    帝国大数据多表列表页加载更多如何查询


    来自为知笔记(Wiz)