找回密码
 立即注册
查看: 668|回复: 0

[分享] 帝国cms插件——帝国cms7.2点击加载更多插件

[复制链接]

2

主题

0

回帖

20

积分

新手上路

积分
20
没留下什么 发表于 2023-10-3 16:55:02 | 显示全部楼层 |阅读模式
在制作移动端页面时会用到,把以下代码添加到服务器,按步骤操作即可实现点击加载更多。


1、将以下代码上传至服务器(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=6;}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.    
  14.     // next:第几页
  15.     // table:调用数据表
  16.     // limit:每次调用数量
  17.     // small_length:简介截取字符数
  18.     // length:标题截取字符数
  19.     // classid:调用栏目,允许多个,如1,2,3,4  特别注意,必须是调用同一数据表的栏目
  20.     // orderby:排序,默认是newstime,传什么就按什么来排序,如 id
  21.     // myorder:正反序,默认是asc,传值怎为desc
  22.     $link=db_connect();
  23.     $empire=new mysqlquery();
  24.     $num =(int)$_POST['next'] *$limit;
  25.      
  26.       if($table){
  27.             $sql=$empire->query("SELECT * FROM `".$dbtbpre."ecms_".$table."` $where order by $orderby $myorder limit $num,$limit");
  28.      
  29.         while($r=$empire->fetch($sql)){
  30.      
  31.             if($r[mtitlepic]==''){
  32.                 $r[mtitlepic]=$public_r[news.url]."e/data/images/notimg.gif";
  33.             }
  34.         $oldtitle=stripSlashes($r[title]);
  35.         $title=sub($oldtitle,'',$length);
  36.         $smalltext=stripSlashes($r[smalltext]);
  37.         $smalltext=sub($smalltext,'',$small_length);
  38.         $classname=$class_r[$r[classid]][classname];
  39.         $newsurl=$public_r[newsurl];
  40.         $classurl=$newsurl.$class_r[$r[classid]][classpath];
  41.         $urls = sys_ReturnBqTitleLink($r);
  42.      
  43.     ?>
  44.     <!-- 以下代码是显示列表的标签模板 -->
  45.     <li class='news-list'>
  46.         <a href='<?=$urls?>' title='<?=$r[title]?>' class='date-link'>
  47.             <img src='<?=$r[mtitlepic]?>' alt='<?=$r[title]?>'  class='date-img-url'/>
  48.             <h4 class='date-title'><?=$r[title]?></h4><span class='act-datetime'><?=date("Y-m-d",$r[newstime])?></span>
  49.         </a>
  50.     </li>
  51.     <?php
  52.         }
  53.        }
  54.     }
  55.     db_close();
  56.     $empire=null;
  57. ?>
复制代码




2、在帝国CMS模板后台,在对应的列表页面添加以下代码


页面模板内容(*)
  1. <ul class="list-content  clear" id="showajaxnews">[!--empirenews.listtemp--]<!--list.var1-->[!--empirenews.listtemp--]</ul>   
  2. <div class="more" id="loadmore">点击加载更多内容</div>
  3. <!-- 需要引入JQ文件 -->
  4. <script src="/skin/fz/js/jquery-1.8.2.min.js" type="text/javascript"></script>
  5. <script>
  6. $(function(){   
  7.      var i = 1; //设置当前页数
  8.     $('#loadmore').click(function(){
  9.         $.ajax({
  10.             url : 'http://localhost/cms/e/action/getmore.php',        // 这是当前服务器的地址
  11.             type:'POST',
  12.             data:{"next":i,'table':'news','classid':'[!--self.classid--]','action':'getmorenews','limit':10,'small_length':120},
  13.             dataType : 'html',
  14.             beforeSend:function(){
  15.                 $("#loadmore").show().html('<img src="/images/loaduai.gif" width=23/>  正在努力加载中...');
  16.                    $('#loadmore').attr('disabled','disabled');
  17.             },
  18.             success : function(data){
  19.                     if(data){
  20.                                $("#showajaxnews").append(data);
  21.                                $("#loadmore").removeAttr('disabled');
  22.                               $("#loadmore").html('点击加载更多');
  23.                         i++;
  24.                     }else{
  25.                         $("#loadmore").show().html("已全部加载完毕!");
  26.                         $('#loadmore').attr('disabled','disabled');
  27.                         return false;
  28.                     }     
  29.             }
  30.         });
  31.     });
  32. });
  33. </script>
复制代码




列表内容模板(list.var) (*)

  1. <li class='news-list'>
  2.     <a href='[!--news.url--]' title='[!--title--]' class='date-link'>
  3.         <img src='[!--titlepic--]' alt='[!--title--]'  class='date-img-url'/>
  4.         <h4 class='date-title'>[!--title--]</h4><span class='act-datetime'>[!--newstime--]</span>
  5.     </a>
  6. </li>
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|IDCeve

GMT+8, 2024-9-17 03:56 , Processed in 0.044646 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表